sizeof(buffer)/sizeof()解决方案
sizeof(buffer)/sizeof()在数据库中存的username的类型是varchar,值是123。C/C++ codeTCHAR username[20]S
sizeof(buffer)/sizeof()
在数据库中存的username的类型是varchar,值是123。
C/C++ codeTCHAR username[20];SQLGetData(hstmt,1,SQL_C_CHAR,username,sizeof(username)/sizeof(TCHAR),&cbsatid);
取出来的数据赋值给username[20],得到的是“123 ”。
这个username和“123”比较,并不相等。。。。
sizeof(username)/sizeof(TCHAR)不就是要得到实际的字符数吗?
[解决办法]sizeof(username)/sizeof(TCHAR)得到的是TCHAR类型的元素的个数。TCHAR username[20];那么sizeof(username)/sizeof(TCHAR)表达式的值为20.
[解决办法]sizeof(username)/sizeof(TCHAR)
可以替换为:
strlen(username)
[解决办法]sizeof(username)/sizeof(TCHAR)
不是在运行期判断的,是在编译期就已经判断了
sizeof(username),里面无论放的是什么,都是20
[解决办法]