help with istream and get()

Hello, i am using the get() function to extract data from a single line of text into multiple fields, split with a comma as a delimiter (,) .

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
                        char temp[61] = { '\0' };

			istr >> m_spotNum;
			istr.ignore();

			istr.get(m_plate, 8, ',');
			//Make uppercase
			for (size_t i = 0; i < strlen(m_plate); i++) {
				m_plate[i] = toupper(m_plate[i]);
			}
			istr.ignore();

			istr.get(temp, 60, ',');
			istr.ignore();

			m_carwash = istr.get();
			istr.ignore(2000, '\n');


and my input is such

12,GVAA123,Nissan Leaf,0<ENTER>
(int),(7 Character Max + Nullbyte),(60 Character limit),(boolean)


For some reason the last value, m_carwash is being set to a char value of some character, which when using debugger to see whats happening, its the fill character after the stream buffer.

is my way of extracting temp from the buffer being done incorrectly? it is to my knowledge it wont discard the delimiter, and that's why I have the ignore() right after.

(UPDATE)
It works if i replace the get() with
 
                        istr >> m_carwash;

But I would still like to know why my first strategy isn't working.
Is there a particular reason that you're using C-strings instead of C++ strings?

Since you want to discard the delimiter, it may be easier to use getline() instead of get().

What type of variable is carwash?

For some reason the last value, m_carwash is being set to a char value of some character,

That's because istream.get() works with C-strings or single characters, not numbers. If you want numbers you will need to use the extraction operator. Remember the number 0 is not the same as the digit 0. Look at an ASCII chart to see the difference.

Topic archived. No new replies allowed.