Hello World. I want to ask how to get the full string from ss to b. And what make exactly stringstream? Is it something like a pointer? Can I delete it when I have finished working with it?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include <iostream>
#include <sstream>
usingnamespace std;
int main () {
char a [12]="Hello World";
stringstream ss;
string b;
ss << a;
ss >> b;
cout << b << endl;
cout << a << endl;
return 0;
}
stringstream, just like most c++ objects have their own internal implementations that enable them to allocate and deallocate memory as needed. Thus eliminating the need for the user to handle this themselves.
To get the full string from ss to b, you can make use of the str method for stringstream objects or use getline seeing as stringstream inherits from istream class:
I want to ask how to get the full string from ss to b.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include <iostream>
#include <sstream>
usingnamespace std;
int main () {
string a ="Hello World";
stringstream ss;
char b [12];
ss << a;
ss >> b;
cout << b << endl;
cout << a << endl;
return 0;
}
Yes, if you follow Smac89's advice. You need to use the str() method to retrieve everthing in the stringstream's buffer.
If you mean each character from a stringstream, you could try a loop and insert a character at a time into a character variable, printing out its value within the loop.