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:

    Painting seems to be to the eye what dancing is to the limbs. When that has educated the frame to self-possession, to nimbleness, to grace, the steps of the dancing-master are better forgotten; so painting teaches me the splendor of color and the expression of form, and as I see many pictures and higher genius in the art, I see the boundless opulence of the pencil, the indifferency in which the artist stands free to choose out of the possible forms.
    Ralph Waldo Emerson (1803–1882)

    Any balance we achieve between adult and parental identities, between children’s and our own needs, works only for a time—because, as one father says, “It’s a new ball game just about every week.” So we are always in the process of learning to be parents.
    Joan Sheingold Ditzion, Dennie, and Palmer Wolf. Ourselves and Our Children, by Boston Women’s Health Book Collective, ch. 2 (1978)

    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)

    The almost unexplored Everglades lay close by and with a half- hour’s start a man who knew the country was safe from pursuit. As one man cheerfully confided ..., ‘A boat don’t leave no trail, stranger.’
    —For the State of Florida, U.S. public relief program (1935-1943)