Thread: Need some help with file input streams

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    5

    Need some help with file input streams

    I'm having some trouble with file input streams.
    I read up on all sorts of functions I could use that I thought might help (get, getline, ignore) but I think I'm coming at this at the wrong angle. This is my function which reads in an N by 2 matrix from a file.

    Code:
    void readGraph ( ifstream& ins, vector< vector<double> > & D,
    				size_t & N )
    {
    	ins >> N;
    	D.resize(N+1);
    	for (size_t r=1; r<=N; r++) 
    	{
    		D[r].resize(3);
    		for (size_t c=1; c<=2; c++) 
    		{
    			//ins >> ch; 
    			//ins.putback(ch);
    			ins >> D[r][c];
    
    		}
    	}	
    }
    My program errors out at 'ins >> D[r][c]' the second time it goes through the for loop (I'm reading in distance graphs, 10 of them in this case.) The error says 'invalid allocation size.' So I'm wondering what is causing that problem and perhaps any thing I can do to fix it.

    Thanks.

    Edit: Forgot to mention that I properly open and close the file in the main program (close it after the for loop, of course).
    Last edited by ProFiction; 10-22-2005 at 11:14 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 09:35 AM
  2. sequential file program
    By needhelpbad in forum C Programming
    Replies: 80
    Last Post: 06-08-2008, 01:04 PM
  3. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 05:02 AM
  4. Inventory records
    By jsbeckton in forum C Programming
    Replies: 23
    Last Post: 06-28-2007, 04:14 AM
  5. File I/O with 2 input and 1 output file
    By Sandy in forum C Programming
    Replies: 1
    Last Post: 04-19-2003, 12:06 PM