输入
输入未知个元素
1 #include<stdio.h> 2 #include<iostream> 3 using namespace std; 4 int main(){ 5 int n; 6 while(scanf("%d",&n)!=EOF){ //空格相间,回车结束 7 cout<<"This is: "<<n<<endl; 8 } 9 cout<<endl; 10 return 0; 11 }
输入带空格string
1 getline(cin,m);
输入未知个元素
1 #include<stdio.h> 2 #include<iostream> 3 using namespace std; 4 int main(){ 5 int n; 6 while(scanf("%d",&n)!=EOF){ //空格相间,回车结束 7 cout<<"This is: "<<n<<endl; 8 } 9 cout<<endl; 10 return 0; 11 }
输入带空格string
1 getline(cin,m);