Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/146.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
反斜杠后追加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 - Fatal编程技术网

反斜杠后追加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的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

找不到驱动器,因为此数组的末尾总是附加一个“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 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这比我现在做的更优雅一点。谢谢!这比我现在做的更优雅一点。谢谢!