两种方式的字符串输入输出

传送门:点击打开链接

样例输入1

3 1 2
1.0 21.2 1

样例输出1

21.2
1
1.0


第一行输n个整数,第二行输n个字符串。。。n未知

方法一:

do{
	scanf("%d",&a[n].x);
	n++;
	s = getchar();
}while(s!='\n');

方法二:

string s;
getline(cin,s);
stringstream ss(s);
while(ss>>x)
{
    a[n++].x = x;
}


猜你喜欢

转载自blog.csdn.net/zxwsbg/article/details/80206857