C++.


         


iostream

. ostringstream

, istringstream , stringstream

, . ,

#include <sstream>

, alice_emma buf

ostringstream. buf

, :

#include <string>

#include <fstream>

#include <sstream>

string read_file_into_string()

{

ifstream ifile( "alice_emma" );

ostringstream buf;

char ch;

while ( buf && ifile.get( ch ))

buf.put( ch );

return buf.str();

}

- str()

  string, ostringstream. , string. , text , buf:

int main()

{

string text = read_file_into_string();

//

vector< string::size_type > lines_of_text;

string::size_type pos = 0;

while ( pos != string::npos )

{

pos = text.find( '\n' pos );

lines_of_text.push_back( pos );

}

// ...

}

ostringstream

, .. , . , , :

#include <iostream>

#include <sstream>

int main()

{

int ival = 1024; int *pival = &ival;

double dval = 3.14159; double *pdval = &dval;

ostringstream format_message;

//

format_message << "ival: " << ival

<< " ival: " << pival << 'n'

<< "dval: " << dval

<< " dval: " << pdval << endl;

string msg = format_message.str();

cout << " : " << msg.size()

<< " : " << msg << endl;

<