#include <iostream>
#include <fstream>
usingnamespace std;
int main(int argc, char *argv[])
{
int x ;
char y[1000] ;
char str[10];
char op [5] ;
cout << "Wait for input: ";
// get input, if the input is not "open", wait for another input
//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();
while (true) {
cin >> op;
if(strcmp(op, "open")== 0) break;
else cout << endl << "Hint: open" << endl << "type again:" ;
}
// 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";
FILE *fp;ss
fp=fopen("G:\\ccc\\example.txt", "r");
system("pause");
}
After the user type in the number and alphabets, if the user type open and pressed enter, i want it open the example.txt(the output file. Its location is: G:\ccc .
Now my main problems is how to open a the file that i mentioned? And yes the fp and fopen is use to open the file, but i don't know why every times i try the program didn't open it and it also didn't gave me any error message.