Cplusplus cin splitting
Cplusplus cin splitting
我有以下代码:
int main()
{
string input = "";
std::vector<int> board = create_board();
print_board(board);
std::stringstream stream;
cout << "Please enter two numbers: ";
getline(cin, input);
stream << input;
cout << stream << endl << endl;
我想做的是从用户那里得到两个数字,中间用空格隔开,以字符串的形式出现。将它们转换为整型,并将这两个整型存储在一个数组中,以便在程序中进一步使用。(我正在用c++为学校编写游戏存储器)。有人能帮帮我吗?
你差不多完成了。
stream << input;
int tmp1, tmp2;
if(stream >> tmp1 >> tmp2)
cout << tmp1 << " "<< tmp2<< endl;
else
// there is error.
相关文章:
- C++中的cin.ignore()函数不适用于整个流
- 在while循环中输入带有std::cin的字符串后,控制台会输出大量胡言乱语
- Problems with std::cin.fail()
- 由cin中的字符串中未捕获空白引起的分割错误
- 在C++中使用Cin,我如何在1行中输入
- 将 cin 限制为只有一个
- cin >> int 给定一个字符串将 int 赋值为 0
- istream std::cin如何修改自定义istream缓冲区
- C++ 将 CIN 值存储到任何类型的数组中
- 为什么无论你输入什么,这"while(cin.get(str,3))"只运行一次?
- cin 的十进制输入验证?
- Turbo C++ cin() 不能与 gets() 一起使用
- 使用 cin 时接受小数点后的 2 位数字
- 在 std::getline 和 std::cin 期间卡在循环中
- 我无法在Visual Studio代码中使用CIN输入答案,它说输入您的年龄,但它说只读文本编辑器如何解决这个问题?
- 为什么我的两个 cin 语句没有在程序结束时运行?
- C++ cin.ignore() 跳过循环
- CIN是逻辑1还是0?
- 如何运行多行 cin?
- Cplusplus cin splitting