1// stringstream::str
2#include <string> // std::string
3#include <iostream> // std::cout
4#include <sstream> // std::stringstream, std::stringbuf
5
6int main () {
7 std::stringstream ss;
8 ss.str ("Example string");
9 std::string s = ss.str();
10 std::cout << s << '\n';
11 return 0;
12}
1// iostream_cerr.cpp
2// compile with: /EHsc
3#include <iostream>
4#include <fstream>
5
6using namespace std;
7
8void TestWide( )
9{
10 int i = 0;
11 wcout << L"Enter a number: ";
12 wcin >> i;
13 wcerr << L"test for wcerr" << endl;
14 wclog << L"test for wclog" << endl;
15}
16
17int main( )
18{
19 int i = 0;
20 cout << "Enter a number: ";
21 cin >> i;
22 cerr << "test for cerr" << endl;
23 clog << "test for clog" << endl;
24 TestWide( );
25}
26
1// EXAMPLE
2ostringstream ssTextAsStream("This is part of the stream."); // declare ostringstream
3string sTextAsString = ssTextAsStream.str(); // converted to string
4cout << sTextAsString << "\n"; // printed out
5
6/* SYNTAX
7<YourStringStream>.str()
8*/
9
10/* HEADERS
11#include <iostream>
12#include <sstream>
13using namespace std;
14*/
1std::stringstream os;
2os << "12345 67.89"; // insert a string of numbers into the stream
3
4std::string strValue;
5os >> strValue;
6
7std::string strValue2;
8os >> strValue2;
9
10// print the numbers separated by a dash
11std::cout << strValue << " - " << strValue2 << std::endl;
12