Write to file: ofstream : Text File « File « C++






Write to file: ofstream

 

 
#include <iostream> 
#include <fstream> 
using namespace std; 
 
int main() 
{ 
  ofstream out("test"); 
  if(!out) { 
    cout << "Cannot open file.\n"; 
    return 1; 
   } 
 
  out << 10 << " " << 123.23 << endl; 
  out << "This is a short text file."; 
 
  out.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.Read from file.Read from file.
5.Reading from a File
6.Writing to a File
7.reading a text file
8.writing on a text file
9.Sequential Files