我正在尝试通过 Windows Wave 设备进行扫描,使用以下测试片段test.cpp
;
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;
}
用 PowerShell 在 PowerShell 中编译gcc version 8.1.0 (i686-posix-dwarf-rev0, Built by MinGW-W64 project)
,我收到此错误:
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 风格的空终止字符串的支持。为什么我会收到此错误?