【发布时间】:2021-04-08 23:46:18
【问题描述】:
我正在尝试通过 windows wave 设备进行扫描,在test.cpp 中使用以下测试 sn-p;
using namespace std;
#include <string>
#include <vector>
#include <Windows.h>
int main ()
{
int nDeviceCount = waveOutGetNumDevs();
vector<wstring> sDevices;
WAVEOUTCAPS woc;
for (int n = 0; n < nDeviceCount; n++)
if (waveOutGetDevCaps(n, &woc, sizeof(WAVEOUTCAPS)) == S_OK) {
wstring dvc(woc.szPname);
sDevices.push_back(dvc);
}
return 0;
}
使用 gcc version 8.1.0 (i686-posix-dwarf-rev0, Built by MinGW-W64 project) 在 PowerShell 中编译,我收到此错误:
PS xxx> g++ .\test.cpp -c
.\test.cpp: In function 'int main()':
.\test.cpp:14:27: error: no matching function for call to 'std::__cxx11::basic_string<wchar_t>::basic_string(CHAR [32])'
wstring dvc(woc.szPname);
我认为wstring 构造函数包括对 c 样式空终止字符串的支持。为什么会出现此错误?
【问题讨论】:
-
This question 是关于将
string转换为wstring但答案仍然适用。 -
如果您的代码页不是 UTF-8 代码页,则必须将字符串正确转换为正确的编码。