Writing to a File : Text File « File « C++






Writing to a File

  
#include <fstream>
#include <iostream>
using namespace std;

int main ()
{
   char data[80];
   ofstream outfile;
   outfile.open("students.dat");
   cout << "Writing to the file" << endl;
   cout << "Enter class name: "; 
   cin.getline(data, 80);
   outfile << data << endl;
   cout << "Enter number of students: "; 
   cin >> data;
   cin.ignore();
   outfile << data << endl;
   outfile.close();
   return 0;
}
  
    
  








Related examples in the same category

1.Use the getline function with the C++ string classUse the getline function with the C++ string class
2.Write strings to disk
3.Write string to a file
4.Write to file: ofstream
5.Read from file.Read from file.
6.Reading from a File
7.reading a text file
8.writing on a text file
9.Sequential Files