[Univ of Cambridge] [Dept of Engineering]
next up previous contents
Next: Casts Up: Input/Output Previous: Input of User-Defined types

String streams

stringstreams are streams that are attached to a string rather than a file and letting you use the same syntax as file I/O. They are defined in <sstream>.
[fontsize=\small,frame=single,formatcom=\color{progcolor}]
#include <iostream>
#include <string>
#include <sstream>
using namespace std;

int main()
{
int i = 7;
string s1 = "He is ";
string s2 = " years old";

ostringstream ostring;
ostring << s1 << i << s2;

cout << "ostring =" << ostring.str() << endl;

return 0;
}



Tim Love
2001-07-05