How to Open File Using Open Method in C++

Free C++ course with real-time projects Start Now!!

Program 1

// open file using Open Method for write
#include<iostream>
#include<fstream>
#define clrscr() system("cls")
using namespace std;
int main()
{
    clrscr();
    fstream fout;
    char name[20];
     char city[20];
     char college[20];
    fout.open("g://cppdata/student.txt",ios::out);
    cout<<"Enter Name: ";
    cin>>name;
    fout<<name;
    fout.close();

    fout.open("g://cppdata/college.txt",ios::out);
    cout<<"Enter College Name: ";
    cin>>college;
    fout<<college;
    fout.close();
    
    cout<<"Enter City Name: ";
    cin>>city;
    fout<<city;
    fout.close();
    cout<<" Multiple file created";
    return 0;

}

 

Your opinion matters
Please write your valuable feedback about DataFlair on Google

follow dataflair on YouTube

Leave a Reply

Your email address will not be published. Required fields are marked *