fopen is the code that return the pointer of a file structure, but i don't know very know how to return the pointer correctly that make the file open.
ofstream is a code use to open the file mentioned.
Code:
ofstream  a_file ( "test.txt", ios::app )
I tried this but still not work as I want(open the out put file/a_file/file with location:G:\ccc\example.txt).

Code:
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <cstdio>

using namespace std;

int main(int argc, char *argv[])
{

    int x ;
    char y[1000] ;
    char str[10];
    char op [5] ;

FILE *fp;
    fp=fopen("g:\\ccc\\example.txt", "r");

    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 ( "G:\\ccc\\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){
                      ofstream a_file ( "g:\\ccc\\example.txt", ios::app ); 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 ( "g:\\ccc\\example.txt" );
    //Reads one string from the file
    b_file>> str;
    //Should output 'this'
    cout<< str <<"\n";
    
    system("pause");
}

Last edited by shabbir; 13Mar2009 at 13:40.. Reason: Local IMG Dropped