代码解释了我想要做的事情
auto haystack = wstring(L"\REGISTRY\MACHINE\SOFTWARE\WOW6432Node\Data\0\Path");
auto needle = wstring(L"\WOW6432Node\Data\0\Name");
auto found = haystack.find(needle) != haystack.npos;
cout << found << endl;
它返回true虽然needle
与haystack
不同,但注意前者以\Path
结尾,而后者以\Name
结尾...我怎么能确切地说出是否确定string包含另一个?
答案 0 :(得分:2)
由于终止&#39; \ 0&#39;字符串比你想象的要短:
href="management/users"
其他非预期的转义序列应该产生编译器警告:
g ++:警告:未知的转义序列:&#39; \ R&#39; (......等等)
您可以查看:http://en.cppreference.com/w/cpp/language/string_literal
答案 1 :(得分:0)
frameBuffer[0] = modify(audioData[0]); // left sample 1
frameBuffer[1] = modify(audioData[1]); // right sample 1
frameBuffer[2] = modify(audioData[2]); // left sample 2
frameBuffer[3] = modify(audioData[3]); // right sample 2
// ...
frameBuffer[2*(n-1)] = modify(audioData[2*(n-1)]); // left sample n
frameBuffer[2*(n-1)+1] = modify(audioData[2*(n-1)+1]); // right sample n
字符是转义字符。要使用实际的\
字符,您需要使用\
来转义它所以您的代码需要像这样更改:
\\.
答案 2 :(得分:0)
你可以这样做:
wstring haystack = wstring(LR"P(\REGISTRY\MACHINE\SOFTWARE\WOW6432Node\Data\0\Path)P");
wstring needle = wstring(LR"P(\WOW6432Node\Data\0\Name)P");
bool found = haystack.find(needle) != haystack.npos;
cout << (char*)(found?"True":"False") << endl;
\ 0对你来说是一个问题,因为它过早地结束了构造函数