Mega Code Archive

 
Categories / C++ Tutorial / File Stream
 

Use ofstream to write text to a file

#include <iostream>     #include <fstream>    using namespace std; main(void)    {      char *p = "hello there";            ofstream out("test");      if(!out) {        cout << "Cannot open file";        return 1;       }            while(*p) out.put(*p++);            out.close();            return 0;    }