class

Discussion in 'C++' started by triplejump24, Dec 13, 2006.

  1. triplejump24

    triplejump24 Guest

    Hi. I basically have all my classes defined and every single function
    defined. but im not sure how to read the files i have into object arrays.
    I dont understand how that works or what format to use. Can anyone help? I
    sort of have this but im not sure if this is what I need to do.
    Video varr[100]
    int nbrVideo'
    nbrVideo = readVideo(varr);

    int readVideo(Video varr[]){
    ? = 0;
    //keep reading until the end {
    read string 1
    string 2
    string 3
    string 4
    Video temp (str 1, str 2, str 3, str 4)
    Varr[?] = temp
    ?++;
    }
    return ?;
     
    triplejump24, Dec 13, 2006
    #1
    1. Advertising

  2. triplejump24

    Guest

    On Dec 13, 6:19 am, "triplejump24" <> wrote:
    > Hi. I basically have all my classes defined and every single function
    > defined. but im not sure how to read the files i have into object arrays.
    > I dont understand how that works or what format to use. Can anyone help? I
    > sort of have this but im not sure if this is what I need to do.
    > Video varr[100]
    > int nbrVideo'
    > nbrVideo = readVideo(varr);
    >
    > int readVideo(Video varr[]){
    > ? = 0;
    > //keep reading until the end {
    > read string 1
    > string 2
    > string 3
    > string 4
    > Video temp (str 1, str 2, str 3, str 4)
    > Varr[?] = temp
    > ?++;}


    return ?;

    Ok, so you want a function that reads Videos from a file and inserts
    them into an array, right? Since I don't know how you store the Videos
    in the file I can't tell you how to read them in but here are some
    general tips:
    1. Don't use an array, use std::vector, it's easier to use and much
    safer.
    2. To read from a file you usually use an fstream:
    #include <fstream>
    int main()
    {
    std::fstream file("filename.txt");
    int i;
    file >> i; // Reads an int from filename.txt
    }
    3. If you don't know how many Videos you have you need to loop, take a
    look at the while-loop in your book.

    --
    Erik Wikström
     
    , Dec 13, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. cyril
    Replies:
    2
    Views:
    3,870
    cyril
    Aug 25, 2004
  2. Purush
    Replies:
    4
    Views:
    1,665
    Purush Rudrakshala
    Apr 13, 2005
  3. E11
    Replies:
    1
    Views:
    4,788
    Thomas Weidenfeller
    Oct 12, 2005
  4. christopher diggins
    Replies:
    16
    Views:
    756
    Pete Becker
    May 4, 2005
  5. Joseph Turian
    Replies:
    5
    Views:
    597
Loading...

Share This Page