2021-8-22 C++一次性读取一行输入进数组(数字之间以空格隔开)


#include<iostream>
#include<string>
#include<sstream>
#include<vector>

using namespace std;

int main() {
        //input:3 2 5 4 6 5 8 7
	string line;
	getline(cin, line);
	stringstream ss(line);
	vector<int> nums;
	int x;
	while (ss >> x)
		nums.push_back(x);

        /* input:
        * 4
        * 2 4 5 1
        */
        int times;
        cin>>times;
        vector<int> nums(times);
        for(int i = 0; i < times; i++){
            int num;
            cin>>num;
            time[i] = num;
        }

	return 0;

}
posted @ 2021-08-22 17:04  shenlei_blog  阅读(1033)  评论(0)    收藏  举报