0

I have a line that has the format (int,int,int,char) and wish to store the three ints into x,y,z and then place the char value into that position in my 3D array. However it is skipping the first number and going to the second. Any help?

void list_Input(char ***&a, const int &f, const int &n)
{
string line;

while (getline(cin, line, ',') && !line.empty())
{
    if (line[0] == '/' )
    {
        continue;
    }
    else
    {
        int y = stoi(line);
        getline(cin, line, ',');
        cout << line;
        int x = stoi(line);
        getline(cin,line,',');
        int f = stoi(line);

        a[z][x][y] = getline(cin,line,')');
    }
}

}

GoBlue_MathMan
  • 1,048
  • 2
  • 13
  • 20

1 Answers1

0

It's hard to tell without seeing your input, but I think what's happening here is you are using ',' as the delimiter each time. What you will find is that this will break if your numbers appear like this:

1,2,3
4,5,6

Notice when you read the third number, there is no comma after it. So the stream will be read until it finds a comma. That is after the first number on the next line. At that point, you're out of sync and skipping over the first number.

paddy
  • 60,864
  • 6
  • 61
  • 103
  • my input would be something like the following: (1,23,92,H) – GoBlue_MathMan Sep 19 '13 at 23:20
  • It would be much safer if you did an ordinary `getline` (delimited by newline, assuming that your input is that way) and then parse the information out of that string. You can still use `getline`, but do it on a `istringstream`. You will have much less scope for problems that way. – paddy Sep 19 '13 at 23:24