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:

    History counts its skeletons in round numbers.
    A thousand and one remains a thousand,
    as though the one had never existed:
    an imaginary embryo, an empty cradle,
    ...
    emptiness running down steps toward the garden,
    nobody’s place in line.
    Wislawa Szymborska (b. 1923)

    People seldom see the halting and painful steps by which the most insignificant success is achieved.
    Anne Sullivan (1866–1936)

    [Wellesley College] is about as meaningful to the educational process in America as a perfume factory is to the national economy.
    Nora Ephron (b. 1941)

    Probably nothing in the experience of the rank and file of workers causes more bitterness and envy than the realization which comes sooner or later to many of them that they are “stuck” and can go no further.
    Mary Barnett Gilson (1877–?)

    The cowboy ... is well on his way to becoming a figure of magnificent proportions. Bowlegged and gaunt, he stands as the apotheosis of manly perfection. Songs, novels, movies, magazines, and operettas have made the least inquiring of us well acquainted with his extraordinary courage, unfailing gallantry, and uncanny skill with gun or lariat. The farmer, meanwhile, sits stolidly on his tractor, bereft of romance and adventure.
    —For the State of Kansas, U.S. public relief program (1935-1943)