Data File - Steps To Process A File in Your Program

Steps To Process A File in Your Program

The five steps to use files in your C++ program are:

  1. Determine the type of link required.
  2. Declare a stream for the desired type of link.
  3. Attach the desired file to the stream.
  4. Now process as required.
  5. Close the file link with stream.

The complete example program:

/*To get rollnumbers and marks of the students of a class (get from the user) and store these details into a file called 'Marks.dat' */ #include void main( ) { ofstream filout ; // stream decided and declared - steps 1 & 2 filout.open("marks.dat", ios :: out) ; // file linked - step 3 char ans = 'y' ; // process as required - step 4 begins int rollno ; float marks ; while(ans == 'y' || ans == 'Y') { cout << " \n Enter Rollno. :" ; cin >> rollno; cout << " \n Enter Marks :" ; cin >> marks ; filout << rollno << " \n " << marks << " \n " ; cout << " \n Want to enter more records?(y/n)..." ; cin >> ans ; } filout.close( ) ; // delink the file - step 5 }

Read more about this topic:  Data File

Famous quotes containing the words steps, process, file and/or program:

    I honor most those to whom I show least honor; and where my soul moves with great alacrity, I forget the proper steps of ceremony.
    Michel de Montaigne (1533–1592)

    The invention of photography provided a radically new picture-making process—a process based not on synthesis but on selection. The difference was a basic one. Paintings were made—constructed from a storehouse of traditional schemes and skills and attitudes—but photographs, as the man on the street put, were taken.
    Jean Szarkowski (b. 1925)

    I have been a soreheaded occupant of a file drawer labeled “Science Fiction” ... and I would like out, particularly since so many serious critics regularly mistake the drawer for a urinal.
    Kurt Vonnegut, Jr. (b. 1922)

    Worn down by the hoofs of millions of half-wild Texas cattle driven along it to the railheads in Kansas, the trail was a bare, brown, dusty strip hundreds of miles long, lined with the bleaching bones of longhorns and cow ponies. Here and there a broken-down chuck wagon or a small mound marking the grave of some cowhand buried by his partners “on the lone prairie” gave evidence to the hardships of the journey.
    —For the State of Kansas, U.S. public relief program (1935-1943)