c++ - 单独地,std::getline() 工作正常,但如果事先有输入,则输出行为异常
问题描述
我想在字符串中输入空格。
例如:"Hello World"
输入:
2
Hello World
Good Morning
期望的输出:
Hello World
Good Morning
但是这段代码不起作用,为什么?
int main()
{
int q;
cin >> q;
string str[q];
int i = 0;
while(q--)
{
getline(cin, str[i]);
cout << str[i] << endl;
i++;
}
return 0;
}
解决方案
推荐阅读
- c# - 在 IIS 上发布后 POST 响应不起作用
- node.js - 有没有办法在nodejs unix环境中使用“js-yaml”将一个YAML文件添加到另一个YAML文件
- sql - Replace 00 with varbinary type
- gtk - GtkApplicationWindow 子类“销毁”两次
- php - PHP替换动态变量
- angularjs-directive - ng-selected 所需的验证不适用于复选框
- mysql - 使用左连接和分组方式重命名查询中的重复结果
- azure - 在 Azure 中的 dockerised App Service 上运行“安装”命令
- regex - 为什么匹配对象 .Value 没有按预期工作?
- php - 通过 php 处理并发 puppeteer 请求