I have a tag like so:
<foo>
and I am trying to extract 'foo' from this.
I'm using a stringstream in a while loop but it seems to fail with the first line, then it works with every other line.
<foo>
and I am trying to extract 'foo' from this.
I'm using a stringstream in a while loop but it seems to fail with the first line, then it works with every other line.
Code:
std::ifstream is("xml.txt"); if(is.fail()) { return 0; } std::string str, tag; std::stringstream ss; while(std::getline(is, str)) { tag = ""; ss.seekg(std::stringstream::beg); ss.str(str); ss.ignore(256, '<'); ss >> tag; std::cout << ss.str()<< " " << tag << "\n"; }
Comment