input of the form: 2 4 1 3 2 1 2 0

Jul 29, 2013 at 11:23am
how can we take an input of the form;
2 4 1 3 2 1 2 0
on the console from the user and then use the integers for further processing;
there is a space after every integer;

i try doing it the following way;
but strtol only converts before the space;

1
2
3
4
5
6
7
8
9
10
cout<<"Enter the Equation : \n";
	cout<<"Equation 1: \n ";
	
	char str[11];	
	fflush(stdin);
	cin.getline(str,11,'\n');
	
	int temp;
	temp = strtol(str,NULL,10);
	cout<<temp;
Last edited on Jul 29, 2013 at 11:30am
Jul 29, 2013 at 11:47am
Last edited on Jul 29, 2013 at 11:47am
Jul 29, 2013 at 11:57am
thanks @tath
Topic archived. No new replies allowed.