Quote:
I will try to make sense of the madness.
Specifically, there are two kinds of streams: sources, and sinks. Sources are the kind of stream that have all the data you ever need, you just have to extract from it. Sinks can take anything in and put it somewhere else, like how water is the universal solvent and flows to the oceans, or tap water to the sewers. An example of a sink stream is cout.
cout itself has a default way of operating. It will print your lines at once, because it is line buffered. This means that you can break up a long cout statement however you want, but cout will be as big as it needs to be to hold a single line. To display the line, you flush it with endl;
cout << "My rage burns with the power of " << 1000000L << " suns!" << endl;
I LOLed when I read this comment in particular. Its even funnier because I have actually felt that way before...
Quote:
But the point is, now we know the terms sink and source. A stringstream can be used either way. When you use it as a source, you're usually not happy with the stream's state because you forget what the stream already has: what you put into it when it was acting like a sink.
Every character is important to the stream. Either you will extract everything and set the stream pointer to indicate a state of emptiness though the interface (operator>>), or you will discard the stream itself and... set the stream pointer to indicate emptiness, through the interface (e.g. clear() ).
My conclusion is, you need to find a default way of operating, like cout, yourself. Maybe you can parse smarter so that it is impossible to be confused like you are in this thread. After all, enums have a defined syntax. There are a number of quick fixes, like clearing exactly where you need to, but I think you need to give real attention to the algorithm.
I mean, I sort of get what it takes to parse an enum:
Find and store an enum keyword.
Find and store an optional identifier.
Counted the opening brace.
Recursively parse the constant=value, expression
Balance the closing brace.
Find a sequence point ( ';' ).
My algorithm does it a little differently, but I wont get into exactly how it works here. If you're interested, feel free to check out the code once I post the next version of ConvertEnumToStrings. And I'm not confused. As a matter of fact, the program is working now.
Quote:
If you put a whole enum into a stringstream, expect to take all of it back out. Or divide it into parts elsewhere, and feed that to a string stream, and take it back out.
I don't put the whole enum into a stringstream. :) Instead, I put each