Problem with tellp()
Hi!
To verify that a stringstream object is "empty", I use tellp() method in this manner:
1 2 3
|
streamstring ss;
[...]
if (ss.tellp() == -1)
|
This code works fine under GCC, but produces an error under MSVC 10.
I think the problem is the comparison with the integer -1.
What is the correct way to use tellp() and what is the correct way to verify that a stringstream object is empty?
Hello,
Use the str() member of streamstring to return a string calss, and then use string.empty()
That's a novel way to test for empty. This returns 0 with gcc
and MSVC10.
1 2 3 4 5 6 7 8 9
|
#include <sstream>
#include <iostream>
int main()
{
std::stringstream ss;
std::cout << ss.tellp() << std::endl;
return 0;
}
|
@kbw:
Ok, but I should compare with a 0 integer value the returned value of tellp() and this is the problem...
If it's specifically a stringstream, I'd recomend going with aiby's suggestion above.
Topic archived. No new replies allowed.