c++ stroring a key and an adjacent value

so i have to read through a file and store a specific key and value from the line using queue's (myqueue.push())

what i'm having trouble with is seperating key = value . where not every line is in this format, essentially how do i find a word and store it based on the fact that it is seperated by the "=" symbol?

EX:

cats = 5
#random_stuff
apple = 9

i have two queue's each one stores a key and a value. any help is much appreciated.
So, basicly the value left from the '=' sign is the key and the one on the right is the value?
you could use
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
    string str, a, b;
    int c;
    getline(/*your file input stream*/, str);
    if (find(str.begin(), str.end(), '=')!=str.end())
    {
       int i;
       for (i=0; str[i]!=' '; i++)
       {
           a.push_back(str[i]);
           }
       i+=3;
       for (; i<str.size(); i++)
       {
           b.push_back(str[i]);
           }
       c=atoi(b.c_str());
       }
Last edited on
Topic archived. No new replies allowed.