字符串流不接受空格?
stringstream doesn't accept white space?
我有以下代码:
std::stringstream ss;
ss << 1 << "a b c";
std::string result;
ss >> result;
std::cout << result << std::endl;
我看到"1a"而不是"1a b c"。
我在某个地方读到,我应该有ss <<std:: noskip。但这没有用。
任何想法?
std::getline(ss, result);
或者直接取string
result = ss.str();
//Try using this for getting whitespace in string
string input;
cout<<"nInput : "<<input;
getline(cin,input);
string result,label;
std::stringstream sstr(input);
while(sstr>>label){
result=result+label+" ";
}
cout<<"nResult : "<<result;
相关文章:
- 为什么线程不接受此输入?
- 函数不接受 X 参数,函数使用默认参数
- C++ boost::asio::ip::tcp::acceptor 有时不接受连接器?
- B不接受8作为输入的是什么?C++
- 如何删除已输入的书以及如何使标题,语言和名称在上面放置空格不会出错?
- C++数组输入不接受一定数量的整数
- C++概念assignable_from不接受 const&-return 运算符=
- 斯堪夫不接受输入
- C++字符数组不接受超过 4 个字符的输入
- CIN不接受C++中带有空格的输入?
- 为什么C++ STL 哈希表 (unordered_map) 不接受向量作为键
- 为什么不接受具有默认分配参数的函数作为 0-arg 生成器?
- 模板接受常量,但不接受文字
- 如何在构造函数中传递 const 引用时强制编译器不接受右值
- 为什么 strtok_r() 只接受字符数组而不接受字符指针
- C++ cout 不接受字符串或带 + 的字符串
- std::cin不接受输入
- 带有openSSL的libwebsocket服务器不接受连接
- 字符串流不接受空格?
- C++ 字符串.比较 不接受空格字符