Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) std::ofstream

 

std::ofstream (abbreviation of 'output file stream') is an STL file I/O output stream.

 

std::ofstream is used to write to a file. To read from a file, use std::ifstream. Both are derived classes from std::fstream.

 

 

 

 

 

Example: CopyFile

 

#include <cassert>
#include <fstream>

//From http://www.richelbilderbeek.nl/CppCopyFile.htm
void CopyFile(const std::string& fileNameFrom, const std::string& fileNameTo)
{
  assert(FileExists(fileNameFrom));
  std::ifstream in (fileNameFrom.c_str());
  std::ofstream out(fileNameTo.c_str());
  out << in.rdbuf();
  out.close();
  in.close();
}

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict