streaming fun

enjoy streaming example in C++

#include “stdafx.h”
#include <iostream>
#include <fstream>
using namespace std;
int
_tmain(int argc, _TCHAR* argv[])
{
    ofstream file( “rdbuf.txt” );
    streambuf *x = cout.rdbuf( file.rdbuf( ) );
    for( int i = 0; i < 20; i ++ )
        cout << “test” << endl; // Goes to file
    cout.rdbuf(x);
    cout << “test2” << endl;

    _gettch( );
    return 0;
}

this code is working perfect in vs2k5.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s