Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • C++

Idiom #148 Read list of integers from stdin

Read a list of integer numbers from the standard input, until EOF.

#include <vector>
#include <iostream>

using namespace std;
vector<int> v;
for(int t;;){
	cin >> t;
	if(cin.eof())
		break;
	v.push_back(t);
}

there must be 2 semicolon in for loop even it is empty
string input = Console.ReadLine();
string[] intlist = input.Split(new char[] {',', ' '});
	
foreach(string item in intlist)
{
  Console.WriteLine(Convert.ToInt32(item));
}

Assumes each integer number is separated by a comma or space

New implementation...