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:

    There must be a solemn and terrible aloneness that comes over the child as he takes those first independent steps. All this is lost to memory and we can only reconstruct it through analogies in later life....To the child who takes his first steps and finds himself walking alone, this moment must bring the first sharp sense of the uniqueness and separateness of his body and his person, the discovery of the solitary self.
    Selma H. Fraiberg (20th century)

    At last a vision has been vouchsafed to us of our life as a whole. We see the bad with the good.... With this vision we approach new affairs. Our duty is to cleanse, to reconsider, to restore, to correct the evil without impairing the good, to purify and humanize every process of our common life, without weakening or sentimentalizing it.
    Woodrow Wilson (1856–1924)

    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)

    The structure was designed by an old sea captain who believed that the world would end in a flood. He built a home in the traditional shape of the Ark, inverted, with the roof forming the hull of the proposed vessel. The builder expected that the deluge would cause the house to topple and then reverse itself, floating away on its roof until it should land on some new Ararat.
    —For the State of New Jersey, U.S. public relief program (1935-1943)