将回车符值传递给std :: string函数时遇到了一些麻烦。
std::string parsedWord;
size_t found = str.find_first_not_of(' ');
if (found == std::string::npos) std::cout << "No non-whitespace characters found\n";
else
{
while (str.compare(found, 1, " ") || str.compare(found, 1, 0x0D )
// The last argument should be a const char*.
{
parsedWord += str[found]; found++;
}
}
我特意要比较值0x0D,因为在Windows系统上新行是CR LF而其他系统使用不同的类型,我只想检查0x0D
答案 0 :(得分:3)
试试这个
while (str.compare(found, 1, " ") || str.compare(found, 1, "\r")