非常奇怪的弦乐和std :: getline行为
Very strange stringstream and std::getline behaviour
我正在用引擎中的地图加载错误进行战斗,最后我找到了它。但是,弦乐和getline似乎有问题...最小代码:
#include <string>
#include <iostream>
#include <sstream>
int main(int argc, char **argv)
{
std::string text = "1!2!6|6|5|";
std::stringstream buffer;
buffer << text; // insert to buffer
std::string temp;
buffer >> temp; // extract
buffer << temp; // then insert again (i need it in my code to count characters)
// and I can't count it before, as in my code the buffer is filled from file
std::string loaded;
std::getline(buffer, loaded, '!'); //should instert "1" to loaded
std::cout << loaded; //and it displays nothing, debugger shows loaded is empty
}
我做错了什么还是一个错误?我正在使用G 4.7 C 11。
在这种情况下,用于从Stringstream中提取字符串,您可能想要:
temp = buffer.str();
而不是:
buffer >> temp;
请参阅:提取格式化(解释)数据与stringstream.str()
相关文章:
- 在 std::getline 和 std::cin 期间卡在循环中
- 确切地说,如何解释 std::getline(stream, string) 函数在C++中填充的字符串
- std::getline没有在while循环中重新请求用户输入
- 如何将 std::getline 转换为模板类型?
- 如何在 std::getline 中自定义分隔符
- 使用std::getline()读取一行
- std::getline with std::fstream
- 在 std::getline() 上使用任何字符作为分隔符
- C++ - 重复 std::getline() 作为用户整数输入?
- std::getline 读取最后一个字符串两次
- std::getline 未产生正确的输出 (C++)
- C STD :: getline / std :: Sort无法正常工作
- std::getline(std::cin, string) 可能因键盘输入失败的方式
- 可以将std::getline()与从std::string中移出的字符串一起使用吗
- 为什么在同一输入上调用std::getline()n次会产生第n个标记化
- std :: getline(输入,d.info)不起作用
- 用弦乐库解析行时的std :: getline问题
- std :: getline()读取马车返回 r,如何避免
- SEGFAULT与STD :: getline一起使用定界线
- progam在std :: getline AM之后停止响应,代码中是否存在错误