0

im reading in from a file that looks like this enter image description here

The goal is to separate the original identifier (S, A, P, I, O, M), the descripter (inside the parenthesis) and the number, which is how many times it cycles. I need to use the cycle times with another function.

Based on their identifier I need to do something with them, but I can't get it to read in properly. here is my current code.

char ldelim('(');
char rdelim(')');
char delimeter('; ');  //The space after the colon fixed a lot, but added some 
                      //new errors.. plus i think thats bad coding

/*this just bypasses that first line without any data. Probably not a good way 
to do it */
getline(metaFile, nothing); 

while(!metaFile.eof())
{
    getline(metaFile, metaCode, ldelim);
    getline(metaFile, metaDesc, rdelim);
    getline(metaFile, metaCycle, delimeter);
    cycles = stoi(metaCycle);

    codes.push_back(metaCode);
    desc.push_back(metaDesc);
    mcycles.push_back(cycles);

    if (metaCode == S)
        cout << "SSSSS\n";
    if (metaCode == P)
        cout << "PPPPP\n";

    if (metaCode == A)
        cout << "AAAAA\n";
    if (metaCode == I)
        cout << "IIIII\n";

    if (metaCode == O)
        cout << "OOOOOO\n";
    if (metaCode == M)
        cout << "MMMMMM\n";
    else{
        cout << metaCode << "\n";
    }

Obviously I'm not going to use those if statements, but I wanted to test what the vector was taking in. Here is what I got back. The first output is with the space after the colon, the 2nd output is without the space after the colon. As you can see its ignoring some values. Is there a better way to do this?

enter image description here enter image description here

Penrose5833
  • 107
  • 2
  • 10
  • please provide a [mcve]. `S`, `O`,`A` etc are not declared, or are they supposed to be `'S'`, `'O'` etc. ? – 463035818_is_not_an_ai Sep 20 '17 at 08:50
  • 2
    Mandatory read: [Why is `iostream::eof` inside a loop condition considered wrong?](https://stackoverflow.com/questions/5605125/why-is-iostreameof-inside-a-loop-condition-considered-wrong) – molbdnilo Sep 20 '17 at 09:00
  • The multi-character literal `'; '` is not the same as the character sequence `"; "`. – molbdnilo Sep 20 '17 at 09:03
  • 1
    First, like @tobi303 says. Second the else always go inside except metacode == 'M', you have put all if in else if, or use switch. – Check Sep 20 '17 at 09:38
  • Thanks, the "why is iostream::eof..." link fixed my problem! – Penrose5833 Sep 20 '17 at 17:48

0 Answers0