Using ofstream to Open a text File and Write to It - C++ File Stream

C++ examples for File Stream:stream

Description

Using ofstream to Open a text File and Write to It

Demo Code

#include <iostream> 
#include <fstream> 

using namespace std; 

int main() /*from  w w  w .j a  v  a  2 s.c  o m*/
{ 
    ofstream outfile("outfile.txt"); 
    outfile << "I'm in a file!" << endl; 
    int x = 200; 
    outfile << x << endl; 
    outfile.close(); 
    return 0; 
}

Related Tutorials