【发布时间】:2014-10-20 13:00:47
【问题描述】:
大家好,我在从 getline 获取输入时遇到未知错误。我的目的是从用户那里获取一个数字和两个字符串作为输入并打印第一个字符串。这是问题代码
#include <iostream>
using namespace std;
int main() {
int t;
cin>>t;
while(t--)
{ string s,p;
getline(cin,s);
getline(cin,p);
cout<<s;
}
return 0;
}
现在当我提供如下输入时:
1
abababa abb
b
它没有打印任何东西。为什么会这样?
【问题讨论】:
-
为什么 yiu 在这里使用
while? -
因为他想循环运行 t 次。他为什么不应该呢?
-
@AdrianMay
My purpose is to take a number and two strings as input from the user and print the first string. -
实际上我的原始代码完全不同,我刚刚编写了这段代码来向您展示我在输入时遇到的问题