Thread: fstream question...

  1. #1
    Registered User
    Join Date
    May 2002

    fstream question...


    i am loading in a binary file into a 2d vector. i have it working but don't understand how it works! lol

    here is the code....

    int widthb[1];
    int heightb[1];
    int value1[1];
    vector <vector<int> > mapdata;
    int LoadMapData()
    	ifstream load;"", ios::binary);
    	if (
    		return false;*)widthb, 2);*)heightb,2);
    	mapxsize = *widthb;
    	mapysize = *heightb;
    	// this is to determine how big the map is.
    		for (int i = 0; i < mapxsize; i++) 
    			for (int j = 0; j < mapysize; j++) 
    				{*)value1, 1);
    				mapdata[i][j] = *value1;
    when i declare value1 as "int value1[1]" if i don't add the little array bit at the end it will not load the correct value when i use the, but i don't understand why. could someone please explain it to me???? or point me to a site that will help me understand it better? Also if anyone can explain why i have had to use pointers in this code, i can use them a little, but do not understand them yet! lol

    Thanks for any help u can give....
    Last edited by werdy666; 09-26-2002 at 03:05 AM.

  2. #2
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    I think it's because you need to pass a character pointer to the read function, so you need to cast the address of value1 (if it's an integer). If you make value1 an array, you always pass the address of the array (don't need to add the & before it).
    int value1;*)&value1, 1);
    mapdata[i][j] = value1;

  3. #3
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. another do while question
    By kbpsu in forum C++ Programming
    Replies: 3
    Last Post: 03-23-2009, 12:14 PM
  2. FStream Question
    By CPP-Null in forum C++ Programming
    Replies: 5
    Last Post: 05-25-2003, 01:28 PM
  3. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 09:22 PM
  4. fstream question!
    By FutureCoder in forum C++ Programming
    Replies: 1
    Last Post: 01-31-2003, 04:06 PM
  5. Problems with fstreams.
    By mosdef in forum C++ Programming
    Replies: 7
    Last Post: 06-19-2002, 03:36 PM