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:

    “What had really caused the women’s movement was the additional years of human life. At the turn of the century women’s life expectancy was forty-six; now it was nearly eighty. Our groping sense that we couldn’t live all those years in terms of motherhood alone was “the problem that had no name.” Realizing that it was not some freakish personal fault but our common problem as women had enabled us to take the first steps to change our lives.”
    —Betty Friedan (20th century)

    “They were steps for me, and I climbed up over them—to do so I needed to go on past them. But they supposed I wanted to settle down on them.”
    —Friedrich Nietzsche (1844–1900)

    “A process in the weather of the world
    Turns ghost to ghost; each mothered child
    Sits in their double shade.
    A process blows the moon into the sun,
    Pulls down the shabby curtains of the skin;
    And the heart gives up its dead.”
    —Dylan Thomas (1914–1953)

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

    “When Paul Bunyan’s loggers roofed an Oregon bunkhouse with shakes, fog was so thick that they shingled forty feet into space before discovering they had passed the last rafter.”
    —State of Oregon, U.S. public relief program (1935-1943)