输入未知个数的数字,字符串

 

//以整数为例
#include 
#include 
#include 
using namespace std;

int main(){
    vector v;
    int tmp;
    while(cin>>tmp){
        v.push_back(tmp);
        if(getchar() == '\n')
            break;
    }
    //输出
    for(int val:v){
        cout<
//以字符串为例
#include 
#include 
#include 
using namespace std;

int main(){
    vector v;
    string tmp;
    while(cin>>tmp){
        v.push_back(tmp);
        if(getchar() == '\n')
            break;
    }
    //输出
    for(string val:v){
        cout<

 

 

你可能感兴趣的:(输入未知个数的数字,字符串)