[Home]  [Edit this page]  [Recent Changes]  [Special Pages]  [Help
CppOfstream

(C++) ofstream

A stream to write to a file. To open a file to write to:
  1. include <fstream>
  2. include <string>
int main() { const std::string fileName = "temp.tmp"; std::ofstream myFile(fileName.c_str()); const std::string myData = "bilderbikkelWasHere"; myFile >> myData; myFile.close(); }
This code will delete the file temp.tmp, then write myData to it.

Ways of opening a file

  • std::ofstream myFile("temp.tmp",std::ios::trunc); 
    Deletes everything in temp.tmp, which is the default.
  • std::ofstream myFile("temp.tmp",std::ios::app); 
Appends the new data at the end of the file.
  • std::ofstream myFile("temp.tmp",std::ios::ate); 
    Sets current position at the end of the file.

Topic links



last edited (November 15, 2006) by bilderbikkel, Number of views: 3049, Current Rev: 7 (Diff)

[Edit this page]  [Page history]  [What links here]  [Discuss this topic]  [Printer Friendly]  

Members

Username:

Password:


Register
Forgot Password?




Programmers Heaven - for .NET, Java, C/C++ and WEB Developers!
© 1996-2008 Community Networks Ltd. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited. Violators of this policy may be subject to legal action. Please read Terms Of Use and Privacy Statement for more information. Development by Tore Nestenius at .NET Consultant - Synchron Data.