mshngo wrote:
Hi,
What would be the best way to check whether an istringstream object has
empty buffer? I wanted to do something like:
istringstream isStr(myStringContent.c_str());
while (isStr_BUFFER_IS_NOT_EMPTY) {
//do something
}
I wanted to know how to implement isStr_BUFFER_IS_NOT_EMPTY. I did some
research on the google but still couldn't find a direct answer. I very
much appreciate your help.
Mingsheng
reading with >> sets the stream status depending on wether the read was
successful or not. If you read it to a string it shouldn't (as far as I
know) fail unless the buffer is empty.
so for example this crappy code I made quickly to test it
#include <iostream>
#include <string>
#include <sstream>
int main() {
std::string blah = "blah blah";
std::istringstream isStr(blah.c_str());
while( isStr >> blah ) {
std::cout << "blah" << std::endl;
}
std::cout << "bleh" << std::endl;
return 0;
}
outputs
blah
blah
bleh
- Jonne Lehtinen