读取一行整数到数组中

C++读取一行整数到数组中

int temp;
vector<int> arr;
while(cin>>temp&&getchar()!='\0')
	arr.emplace_back(temp);
	

java读取一行整数到数组中

Scanner in = new Scanner(System.in);
int x = 0;
if (in.hasNextInt()) x = in.nextInt();
List<Integer> list = new ArrayList<>();
while (in.hasNextInt()) {
     list.add(in.nextInt());
}
上一篇:2021-03-01


下一篇:Scanner类输入(部分)