在反斜杠后附加 w 的 TCHAR 数组
TCHAR array appending w after backslash
我正在编写一个带有多字节字符的C++ MFC应用程序,并且我正在尝试迭代运行驱动器号以检查USB连接。我的这部分代码开始在调试模式下给我带来一些问题:
for(int i = 0; i < 26; i++){
...
//Possible device path
TCHAR drivePath[3] = {_T('A'+i), _T(':'), _T('')};
...
}
永远不会找到驱动器,因为此数组总是在末尾附加一个"w"。
例如,对于 i=0
,drivePath=A:w
我的假设是它与多字节/Unicode 相关,但我假设通过使用 TCHAR
和 _T
,它会解决这个问题。
有什么问题吗?
您从未以空字符终止数组。
TCHAR drivePath[3] = {_T('A'+i), _T(':'), _T('')};
应该是
TCHAR drivePath[4] = {_T('A'+i), _T(':'), _T(''), _T(' ')};
// or
TCHAR drivePath[] = {_T('A'+i), _T(':'), _T(''), _T(' ')};
// ^^ let the compiler figure out the size
还有另一种选择:
TCHAR drivePath[] = { _T("A:\") };
for (char ch = 'A'; ch <= 'Z'; ch++){
//Possible device path
drivePath[0] = ch;
}
相关文章:
- Mongodb c++驱动程序:如何查询元素的数组
- 将数组的地址分配给变量并删除
- 从C++本机插件更新Vector3数组
- lambda参数转换为constexpr技巧,然后获取带链接的数组
- 将数组作为参数传递给函数安全吗?作为第三方职能部门,可以探索他们想要的之外的其他元素
- 数组索引的值没有增加
- 将对象数组的引用传递给函数
- 为char数组调整zlib-zpipe
- 2D数组来自文本输入,中间有空格
- std::向量与传递值的动态数组
- 在c++中用vector填充一个简单的动态数组
- 检查TCHAR数组输入是否为带符号整数C++
- 在反斜杠后附加 w 的 TCHAR 数组
- TCHAR数组的深度副本被截断
- C++-检查TCHAR数组是否为空
- 如何在VC++中将TChar[]数组转换为std::string.语法帮助
- 如何编组二维TCHAR数组
- c++ TCHAR数组在VS2010中不工作
- 从TCHAR数组中获取文件扩展名
- 如何将TCHAR数组转换为std::string