Input file stream parsing

Hi all.
I have an assignment for school and one of the requirements is to read in from a file of a specific format and do operations on a data structure based on that input.
The format for the input is as follows:

4

insert 1,5,10,9,7,4

search 5

end

The problem that I'm reaching is when I try to read in the number "10". I am trying to store each number in an array of integers, but I am reading in the characters one by one, meaning when I get to the number 10 I will read in 1 and then 0 as two separate numbers. I'm sure there is some function on input streams to do what I want but I couldn't find it.
Here is the snippet of my code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//Keep reading input while there still is input
  char operation;
  char peek;
  //This highest number of values you can insert on one line is 50
  int inputArray[50];
  int numOfInputs;
  while(!inputFile.eof())
  {
    //Read in the next operation to be done
	inputFile>>operation;
	
	if(operation == 'i')
	{
	  //Next operation is an insert
	  for(int i = 0; i < 5; i++)
	  {
	    //Read the rest of the word insert insert
		inputFile>>operation;
	  }
	  
	  //Next read in all the numbers to be input
	  bool flag = true;
	  numOfInputs = 1;
	  do
	  {
	    //Peek at the next character
	    peek = inputFile.peek();
		//Check if the next character is a number
		if(peek >= 48 && peek <= 57)
		{
		  //Next character was a number
		  int i = 0;
		  inputFile>>inputArray[0];
		  numOfInputs++;
		  peek = inputFile.peek();
          while(peek != ',')
          {
		    ////////
			//As you can see here I am  reading in a multi-digit number
			//to multiple indexes in an array of ints when I want the
			//multi digit number to be placed in one index of the array
			////////
		    inputFile>>inputArray[i];
			i++;
			peek = inputFile.peek();
          }		  
		}
		else if(peek == 44)
		{
		  //Next character is a comma, meaning there is a number afterwards
		  //Take out the comma
		  inputFile>>operation;
		}
		else
		{
		  //Next character is a letter, meaning a new operation
		  //Break out of the do-while loop
		  flag = false;
		}
		
		//********************
		//Do the input operation here
		//********************
		
	  }while(flag);
	}
	else if(operation == 's')
	{
	  //Next operation is a search
	}
	else if(operation == 'e')
	{
	  //The list of operations is over
	}
  }


Any help is greatly appreciated.
You can read a number as characters then convert it to int as follows:
1
2
3
4
5
6
7
8
9
10
11
12
for(int j=0;j<str.size()-1;j++)
		{
			if(str[i][j+1]==',')
			{
				num += str[j]-'0';
				break;
			}
			if(isdigit(str[j]))
				num += str[j]-'0';
			if(isdigit(str[j+1]))
				num*=10;
		}

This reads numbers in a string that looks like this "12,68,944,8333,383393"
the variable int will hold
12
68
944
8333
383393

then you can stre these values in an array.
You should also
#include<cctype>
To allow you to use the function
isdigit();
Topic archived. No new replies allowed.