Thursday, July 19, 2007

Example of C++ with Output

// writing on a text file
#include
#include
using namespace std;
int main () {
ofstream myfile ("example.txt");
if (myfile.is_open())
{
myfile << "This is a line.\n"; myfile << "This is another line.\n"; myfile.close(); } else cout << "Unable to open file"; return 0; }



Output:

[file example.txt]
This is a line.
This is another line.

No comments: