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:

    Let there be no steps backward. A thought as to the manliness of persevering, of the want of manliness in yielding to depression, came to his rescue.
    Anthony Trollope (1815–1882)

    ... geometry became a symbol for human relations, except that it was better, because in geometry things never go bad. If certain things occur, if certain lines meet, an angle is born. You cannot fail. It’s not going to fail; it is eternal. I found in rules of mathematics a peace and a trust that I could not place in human beings. This sublimation was total and remained total. Thus, I’m able to avoid or manipulate or process pain.
    Louise Bourgeois (b. 1911)

    A common and natural result of an undue respect for law is, that you may see a file of soldiers, colonel, captain, corporal, privates, powder-monkeys, and all, marching in admirable order over hill and dale to the wars, against their wills, ay, against their common sense and consciences, which makes it very steep marching indeed, and produces a palpitation of the heart.
    Henry David Thoreau (1817–1862)

    Oh Death he is a little man,
    And he goes from do’ to do’ ...
    —Federal Writers’ Project Of The Wor, U.S. public relief program (1935-1943)