-
December 1st, 2005, 09:05 AM
#1
Reusing std::stringstream after EOF
Hi all,
I´m using a std::stringstream and filling it with several lines. I need to print these lines 2 times and I´m not getting to use it at the second time. I presume that the eofbit is set after the first use so I need to clear it before any other operation. The problem is that even if I clear the bit ( If I´m doing it correctly) the seek(0) dosen´t work, for exemple:
Code:
std::stringstream strtest;
strtest << "aaa bbb cccc" << std::endl;
strtest << "ddd eee ffff" << std::endl;
strtest << "ggg hhh iiii" << std::endl;
std::string teste;
//---- if I comment 2 of these extrations lines the seek(0) works ok
//---- (Because the EOF is not reached....)
strtest >> teste;
strtest >> teste;
strtest >> teste;
strtest >> teste;
strtest >> teste;
strtest >> teste;
strtest >> teste;
strtest >> teste;
strtest >> teste;
strtest >> teste;
strtest.unsetf(std::ios::eofbit);
strtest.unsetf(std::ios::failbit); //--- for safe
strtest.unsetf(std::ios::badbit); //--- "
strtest.seekg(0);
//--- second extration (dosen´t work....)
strtest >> teste;
strtest >> teste;
strtest >> teste;
strtest >> teste;
strtest >> teste;
strtest >> teste;
strtest >> teste;
strtest >> teste;
strtest >> teste;
Can anyone tell me what is wrong???
thank you in advance.
-
December 1st, 2005, 09:33 AM
#2
Re: Reusing std::stringstream after EOF
I don't think that you can use those constants with unsetf (which
expects format flags , not io state flags).
Just use clear() before the seekg ...
Code:
strtest.clear();
strtest.seekg(0);
-
December 1st, 2005, 10:15 AM
#3
Re: Reusing std::stringstream after EOF
Ok Philip, is it! Thank you very much.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|