File handling with Array filled with a class

This is a discussion on File handling with Array filled with a class within the C++ Programming forums, part of the General Programming Boards category; >> Would appreciate any help. I think it would be best to start a separate thread and post your code ...

  1. #16
    Registered User
    Join Date
    Jan 2005
    Posts
    7,328
    >> Would appreciate any help.

    I think it would be best to start a separate thread and post your code and the exact error message. These types of errors can have many different causes.

  2. #17
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,189
    Persoanlly, I woudl just treat the class as if it were a struct. The member functions are only contextual, they dont actually occupy space in the object. You may want to use #pragma pack(1) to guarantee the smallest footprint
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

  3. #18
    Registered User
    Join Date
    Jun 2008
    Posts
    2
    I declare it in my class and when I wnat to use the function as below I get the error message No match for operator[]. If I remove the line dayReport[i].dayOfMonth = dayP then it works but it is not read into the array.

    Code:
    istream& operator >> (istream& fin, weatherReport dayReport[])
    {
        Do something
        dayReport[i].dayOfMonth = dayP;
    }

  4. #19
    Registered User
    Join Date
    Jan 2005
    Posts
    7,328
    I think you should be reading into a weatherReport & instead of into the array. That's just how it's done in C++. Move the code that loops through the array into a separate function and read into each weatherReport one at a time.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File being filled with NULLs
    By Tigers! in forum Windows Programming
    Replies: 2
    Last Post: 06-30-2009, 05:28 PM
  2. #include header files or .cpp files?
    By DoctorX in forum C++ Programming
    Replies: 3
    Last Post: 12-23-2006, 11:21 AM
  3. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  4. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 09:46 AM
  5. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21