Page 3 of 3

question again

Posted: Thu Nov 06, 2008 10:28 am
by WINPINPH1
#include <fstream>
#include <iostream>

using namespace std;

int main()
{
char str[10];

//creates an instance of ofstream, and opens example.txt
ofstream a_file ("example.txt");
//output to example.txt through a_file
a_file<<"This text will now be inside of example.txt ";
//close the file stream explicitly
a_file.close();
//opens for reading the file
ifstream b_file ("example.txt");
//read one string from the file
b_file>>str ;
//should output 'this'
cout<<str <<"\n";
//b_file is closed implicitly here
cin.get();
}

the output in the console is 'this' what if i want the output is 'this text' or all of the string what should i modify to achieve my goal?

tia.