the delimiter is comma, is it not possible to change the delimiter in cin for the next field input?
something like
cin >> setw(8) >> setdel(',') >> m_plate;
Or maybe it's more complicated than that?
How would a loop fit into my code, that would require I grab each character individualy in the stream untill the comma is reached correct?
...is it not possible to change the delimiter in cin for the next field input?
cin is an object representing the input stream. operator>> is what is delimited by whitespace.
If you want to delimit input by another character other than whitespace, you can use std::getline. Your use of istream.get is essentially the same thing except you need to pre-allocate the char* buffer.
For example,
1 2 3 4 5
string line;
while (getline(cin, line, ','))
{
cout << line << '\n';
}
This apply to any input stream, not just cin, btw.
Alternative example, essentially is the same thing you did:
Neither of our codes would handle m_plate or temp being greater than 8 or 60 characters, respectively. If you don't trust your input, that is something to think about.
I was just pointing out something to think about in the future. I don't think it's too important at this stage. so I don't have a robust solution on hand.
It's more just something to think about: If you don't trust the input coming into your program, how should you,
(1) check that it's invalid, and (2) deal with it if it is invalid.
Also, think about how flexible you want your input to be. For example, should it be an error if your line begins with
5 ,
instead of
5,
Just stuff to think about.
The best way to check your own assumptions to form a hypothesis and test it.