Writes the numbers from 1 to 100 to a file called NUMS.1. - C++ File Stream

C++ examples for File Stream:stream

Description

Writes the numbers from 1 to 100 to a file called NUMS.1.

Demo Code

#include <fstream>
#include <iostream>
using namespace std;
ofstream        fp;//from   w ww  . j  av a 2  s .  com
void main()
{
   int ctr;
   fp.open("NUMS.1", ios::out);   // Creates a new file.
   if (!fp)
      {  cout << "Error opening file.\n"; }
   else
   {
      for (ctr = 1; ctr < 101; ctr++)
         {  fp << ctr << " "; }
      }
      fp.close();
      return;
}

Related Tutorials