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:

    Ah, Sun-flower, weary of time,
    Who countest the steps of the Sun,
    Seeking after that sweet golden clime
    Where the traveller’s journey is done:
    Where the Youth pined away with desire,
    And the pale Virgin shrouded in snow
    Arise from their graves, and aspire
    Where my Sun-flower wishes to go.
    William Blake (1757–1827)

    Yet I doubt not through the ages one increasing purpose runs,
    And the thoughts of men are widened with the process of the suns.
    Alfred Tennyson (1809–1892)

    While waiting to get married, several forms of employment were acceptable. Teaching kindergarten was for those girls who stayed in school four years. The rest were secretaries, typists, file clerks, or receptionists in insurance firms or banks, preferably those owned or run by the family, but respectable enough if the boss was an upstanding Christian member of the community.
    Barbara Howar (b. 1934)

    Texas is a heaven for men and dogs but hell for women and oxen.
    —Administration in the State of Texa, U.S. public relief program (1935-1943)