16,548
社区成员




用来读取身份证的
unsigned char msg[200];
0-30是名字
31-33是性别
string str((char*)msg);
CString name = str.substr(0,30).c_str();
CString gender = str.substr(31,3).c_str(); -->这里就报错了。
string str((char*)msg);
这一句执行之后,str的内容是什么样子的。
substr在两种情况下会抛出异常:
If pos is greater than the string length, an out_of_range exception is thrown.
A bad_alloc exception is thrown if the function needs to allocate storage and fails.
估计是pos越界了吧。str字符串的长度很可能不足32(0->31)个。