help reading files


peek
poll
pop
poke 1369
push 42
push 43
push 16
poll
pop
poll
push 13
poll
peek
push 69
poll
push 23 skidoo
poll
peek
push 0849
poll
peek
pop
poll
pop
poll
pop
poll
pop
poll
baz
pop
poll
pop
poll
push 13
push 69
push 08
push 49
push 85
push 31
push 85
push 01
push now is the time for all good men
poll
peek
poke 911
poll
peek
poll
pop
poll
pop
poll
bar
pop
poll
pop
poll
pop
poll
pop
poll
pop
poll
pop
poll
pop
poll
foo


I am trying to read this file but i cant seem to get the strings and the numbers
separated as some lines have number and others don't

I tried

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
    // open the file for input
    ifstream dataFile("STACKTEST.txt", ifstream::in);

    // variables
    string name;
    int val;

    // if the file was successfully opened, continue
    if(dataFile.fail())
    {
        cout << "Error opening file\n";
    }else{
        while(!dataFile.eof())

            dataFile >> name;
            dataFile >> val;
            cout << name << " " << val << endl;
    }


I know getline() can separate lines with a delimiter but how i get the numbers and string seperate
Last edited on
while the file is OK for reading
    read in the first word of the line
    if the word is 'push'
        read in the rest of the line
        process push command
    else
        process command
Topic archived. No new replies allowed.