今天上午的考试又让我学会了不少东西,主要是学会了getline 和stringsteam 这两个神器,getline是读入字符串,遇到回车就会停止
而stringstream是字符串流。差不多是这个流程
示范 代码
#include <iostream>
#include <cstring>
#include <sstream>
using namespace std;
const int N = 110;
int a[N];
int main()
{
int T; cin >> T;
getchar();
while (T--)
{
string str;
getline(cin, str);
cout << str << endl;
stringstream s(str);
int pos = 0;
while (s >> a[pos]) pos++;
for (int i = 0; i < pos; i++)
{
cout << a[i] << endl;
}
}
return 0;
}