File stream function problem

This is a discussion on File stream function problem within the C++ Programming forums, part of the General Programming Boards category; Hi newbie here having a problem at R/T with the following function. It is giving me a application error when ...

  1. #1
    Registered User
    Join Date
    Nov 2004
    Posts
    2

    File stream function problem

    Hi newbie here having a problem at R/T with the following function. It is giving me a application error when the program is run, but compiles just fine.

    Function call:
    Code:
    student::readfile(filename, ctr, ARRAY);

    Function:
    Code:
    void student::readfile(string file, int &ctr, student* arr[])
    {
    	ifstream in(file.c_str(), ios::binary);
    	if(!in)
    	{
    		throw studentX("No file");
    	}
    	for(int i=0; i<ctr; i++)
    	{
    		in.read((char*)arr[i], sizeof(student));
    	}
    }
    Thanks in advance for any ad all help.

    :-) James

  2. #2
    High Flyer stumpster123's Avatar
    Join Date
    Mar 2005
    Posts
    26
    Try using this call instead

    Code:
    student::readfile(filename, &ctr, ARRAY);

  3. #3
    Registered User
    Join Date
    Nov 2004
    Posts
    2
    Thanks, i tried that but got an error while compiling. But i don't think i would want to use reference in this case. I am reading info in from the file and then contiuning to add to an array.

    James

  4. #4
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    917
    then just make the declaration a straight int as well.
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Straight Insertion Sort function problem
    By StaticKyle in forum C++ Programming
    Replies: 6
    Last Post: 05-12-2008, 05:03 AM
  2. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 05:02 AM
  3. Inventory records
    By jsbeckton in forum C Programming
    Replies: 23
    Last Post: 06-28-2007, 05:14 AM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 06:06 PM
  5. qt help
    By Unregistered in forum Linux Programming
    Replies: 1
    Last Post: 04-20-2002, 10:51 AM

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