Problem with istringstream in C++
- by helixed
Hello,
I'm sure I'm just doing something stupid here, but I can't quite figure out what it is. When I try to run this code:
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main(int argc, char *argv[])
{
string s("hello");
istringstream input(s, istringstream::in);
string s2;
input >> s2;
cout << s;
}
I get this error:
malloc: *** error for object 0x100016200: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
The only thing I can think of is that I allocated s2 on the stack, but I thought strings manage their own content on the heap. Any help here would be appreciated.
Thanks,
helixed