[Home]
[Edit this page]
[Recent Changes]
[Special Pages]
[Help]
CppOfstream
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
CppOfstream
(C++) ofstream
A stream to write to a file. To open a file to write to:This code will delete the file temp.tmp, then write myData to it.int main() { const std::string fileName = "temp.tmp"; std::ofstream myFile(fileName.c_str()); const std::string myData = "bilderbikkelWasHere"; myFile >> myData; myFile.close(); }
- include <fstream>
- include <string>
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);
std::ofstream myFile("temp.tmp",std::ios::ate);Sets current position at the end of the file.
Topic links
- #include
- ::, scope operator
- assert
- char
- const
- #include
- int
- iostream
- main
- return
- scope operator'::'
- std
- std::string
- string
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
