Hello, I am a beginner. I read this page already, but just one things that I don't understand. How to open the example.txt when i type open? And the code below is the whole code.
Code:#include <fstream>
#include <iostream>
using namespace std;
int x ;
char y ;
char op ;
int main()
{
int x ;
char y[1000] ;
char str[10];
char op [5] ;
//Creates an instance of ofstream, and opens example.txt
ofstream a_file ( "example.txt" );
// Outputs to example.txt through a_file
cout<<"type some numbers :";
cin>> x ;
a_file<<"number :" <<x ;
cout<<"type some alphabet :";
cin>> y ;
a_file<<"alphabet: "<<y ;
cin.ignore();
// Close the file stream explicitly
a_file.close();
//Opens for reading the file
ifstream b_file ( "example.txt" );
//Reads one string from the file
b_file>> str;
//Should output 'this'
cout<< str <<"\n";
cin.get(); // wait for a keypress
// b_file is closed implicitly here
}