| re: istringstream question
Viet Le Hong wrote:[color=blue]
> That was the code I have written in my program, sorry I could not post
> all my program because it's quite long. The next light function read new
> line from a file, I have check the function and it works fine. The
> problen happens after the >> call in the read eye part, it does not
> change the value of "command" variable at all.
> Thanks[/color]
What might have happened, is that the stream object is put into an
invalid state by one of the read operations. You should generally
test the state of a stream after every read. The clear () member
function is used to reset the state.
The comp.lang.c++ FAQ (Google for C++ FAQ) has a good section on IO
which is almost certain to help you get your code working.
Regards,
Buster.
[color=blue]
> Viet
> camera res;
>
>
> string command;
> // read image size
> next_line();
> istringstream ss(buffer);
> ss >> command;
> if (command!="IMAGESIZE")
> throw parser_error_exception("Invalid image size command when
> reading camera");
> else
> {
> int width, height;
> ss >> width >> height;
> res.set_image_size(width,height);
> }
>
> // read eye
> next_line();
> ss.str(buffer);
> ss >> command;
> if (command!="EYE")
> throw parser_error_exception("Invalid eye command when reading
> camera");
> else
> {
> double x,y,z;
> ss >> x >> y >> z;
> res.set_eye(x,y,z);
> }[/color] |