反斜杠后追加w的TCHAR数组 我正在用多字节字符编码C++ MFC应用程序,我试着迭代地通过驱动器号检查USB连接。这部分代码开始在调试模式下给我带来一些问题: for(int i = 0; i < 26; i++){ ... //Possible device path TCHAR drivePath[3] = {_T('A'+i), _T(':'), _T('\\')}; ... } for(int i=0;i
找不到驱动器,因为此数组的末尾总是附加一个“w” 例如,对于反斜杠后追加w的TCHAR数组 我正在用多字节字符编码C++ MFC应用程序,我试着迭代地通过驱动器号检查USB连接。这部分代码开始在调试模式下给我带来一些问题: for(int i = 0; i < 26; i++){ ... //Possible device path TCHAR drivePath[3] = {_T('A'+i), _T(':'), _T('\\')}; ... } for(int i=0;i,c++,arrays,mfc,char,multibyte,C++,Arrays,Mfc,Char,Multibyte,找不到驱动器,因为此数组的末尾总是附加一个“w” 例如,对于i=0,drivePath=A:\w 我的假设是它与多字节/unicode相关,但我假设通过使用TCHAR和\u T,它会解决这个问题 有问题吗?您从未使用空字符终止数组 TCHAR drivePath[3] = {_T('A'+i), _T(':'), _T('\\')}; 应该是 TCHAR drivePath[4] = {_T('A'+i), _T(':'), _T('\\'), _T('\0')}; // or TCHAR d
i=0
,drivePath=A:\w
我的假设是它与多字节/unicode相关,但我假设通过使用TCHAR
和\u T
,它会解决这个问题
有问题吗?您从未使用空字符终止数组
TCHAR drivePath[3] = {_T('A'+i), _T(':'), _T('\\')};
应该是
TCHAR drivePath[4] = {_T('A'+i), _T(':'), _T('\\'), _T('\0')};
// or
TCHAR drivePath[] = {_T('A'+i), _T(':'), _T('\\'), _T('\0')};
// ^^ let the compiler figure out the size
您从未使用空字符终止数组
TCHAR drivePath[3] = {_T('A'+i), _T(':'), _T('\\')};
应该是
TCHAR drivePath[4] = {_T('A'+i), _T(':'), _T('\\'), _T('\0')};
// or
TCHAR drivePath[] = {_T('A'+i), _T(':'), _T('\\'), _T('\0')};
// ^^ let the compiler figure out the size
还有另一种选择:
TCHAR drivePath[] = { _T("A:\\") };
for (char ch = 'A'; ch <= 'Z'; ch++){
//Possible device path
drivePath[0] = ch;
}
TCHAR驱动路径[]={u T(“A:\\”)};
对于(char ch='A';ch和另一种选择:
TCHAR drivePath[] = { _T("A:\\") };
for (char ch = 'A'; ch <= 'Z'; ch++){
//Possible device path
drivePath[0] = ch;
}
TCHAR驱动路径[]={u T(“A:\\”)};
for(char ch='A';ch这比我现在做的更优雅一点。谢谢!这比我现在做的更优雅一点。谢谢!