Skip to main content

Read & Write in File in C++


 #include<bits/stdc++.h>
using namespace std;

int main()
{
    // Read data from file
    string b;
    ifstream as("Ok.txt");
    while (as.eof()==0){
        getline(as, b);
        cout<<b<<endl;
    }

          // It will write "Ok brother " in Ok.txt file
         
//   ifstream in("Ok.txt");
//  ofstream mk("Ok.txt");
//  mk<<"Ok brother";
//  cout<<"\nWriting successfully! \n";
//  getline(in,a);   

    return 0;
}

Comments