Wednesday, 6 June 2012

C++ Program implementing File Streaming :Storing array of numbers in a data file

C++ Program implementing  File Streaming :Storing array of numbers in a data file


  
#include <stdlib.h>
#include <iostream.h>
#include <fstream.h>

int main()
{
ifstream fin;                      // File Pointers      
ofstream fout;

int array[4] = { 3, 76, 5, 12 };   // Array of data to be saved
int x;                             // Loop Counter

fout.open("fstream.txt");      // Create file
for( x = 0; x < 4; x++ )
  {
      fout << array[x] << endl;         // Write array data to file
  }
  cout<<"Data Has Been Writen..." << endl;    // fstream.txt can be found
                                              // @ C:
  getch();
  fout.close();    // Closes file
  return 0;

0 comments:

Post a Comment

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More