嗨,大家好,请检查此代码。我想创建一个程序,在该程序中我将被提示输入名字和姓氏,然后按时间顺序输出它,而不必为每个名字和姓氏创建变量。与while循环的C++数组
#include<iostream>
using namespace std;
int main(){
int fname[9];
int lname[9];
int x;
while (x < 10){
cout<<"Enter first name: ";
cin>>fname[0];
cout<<"Enter last name: ";
cin>>lname[0];
x = x + 10;
}
x = 0;
while (x < 10){
cout<<fname[0]<<" "<<lname[0]<<"\n";
x = x + 1;
}
return 0;
}
为什么使用int数组输入文本? – NathanOliver
'while(x <10){/*...*/ x = x + 10;}'只会执行一次。第二个'while'循环被破坏:你写了相同的东西10次。 – user463035818
so string fname [0] =“”;那么循环如何?我需要按顺序存储数据,然后打印出来。 – nyelnyelnyel