R
Rafal 'Raf256' Maj
Hi,
I need to parse a file. This means reading from it as from std::istream.
But - sometimes I also need to put-back some text I read before.
What type of string can I use for that? Something like:
void cLine::Load(std::istream &data) {
data.ignore(4); // ignore word "line"
char c; // ignore { and } chars
data >> c >> x1 >> y1 >> x2 >> y2 >> c;
}
void Parse(std::istream &data) { // <------
cStr token;
data >> token;
if (token == "line") line.Load(data);
else if (token == "rect") ....
else ParseError();
}
Syntax of file is for example:
line{1 2 3 4}
Problem is that main Parser must read "line" to know what object to
construct and load, and later load of this object also needs to read same
"line" because this is the syntax.
I need to parse a file. This means reading from it as from std::istream.
But - sometimes I also need to put-back some text I read before.
What type of string can I use for that? Something like:
void cLine::Load(std::istream &data) {
data.ignore(4); // ignore word "line"
char c; // ignore { and } chars
data >> c >> x1 >> y1 >> x2 >> y2 >> c;
}
void Parse(std::istream &data) { // <------
cStr token;
data >> token;
if (token == "line") line.Load(data);
else if (token == "rect") ....
else ParseError();
}
Syntax of file is for example:
line{1 2 3 4}
Problem is that main Parser must read "line" to know what object to
construct and load, and later load of this object also needs to read same
"line" because this is the syntax.