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 to, steps, process, file and/or program:

    “Surely it is one of the requisites of a tasteful garb that the expression of effort to please shall be wanting in it; that the mysteries of the toilet shall not be suggested by it; that the steps to its completion shall be knocked away like the sculptor’s ladder from the statue, and the mental force expended upon it be swept away out of sight like the chips on the studio floor.”
    —Elizabeth Stuart Phelps (1844–1911)

    “Every true man is a cause, a country, and an age; requires infinite spaces and numbers and time fully to accomplish his design;—and posterity seem to follow his steps as a train of clients.”
    —Ralph Waldo Emerson (1803–1882)

    “A designer who is not also a couturier, who hasn’t learned the most refined mysteries of physically creating his models, is like a sculptor who gives his drawings to another man, an artisan, to accomplish. For him the truncated process of creating will always be an interrupted act of love, and his style will bear the shame of it, the impoverishment.”
    —Yves Saint Laurent (b. 1936)

    “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)

    “To motorists bound to or from the Jersey shore, Perth Amboy consists of five traffic lights that sometimes tie up week-end traffic for miles. While cars creep along or come to a prolonged halt, drivers lean out to discuss with each other this red menace to freedom of the road.”
    —For the State of New Jersey, U.S. public relief program (1935-1943)