Hello,
I have made a function which looks like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
void MapRead(int ** a, int rows, int cols, int level){
stringstream ss;
ss << level << ".aem";
ifstream LoadMap(ss.str().c_str());
LoadMap >> rows >> cols;
// allocation
a = newint*[rows];
for(int i = 0; i < rows; i++){
a[i] = newint[cols];}
// initialization
for(int j = 0; j < rows; j++){
for(int i = 0; i < cols; i++){
LoadMap >> a[j][i];}}
LoadMap.close();
}
To load a file which looks like this (1.aem):
5 5 1 0 2 1 0 4 1 1 1 0 0 1 5 0 6 6 1 0 3 8 0 4 1 1 7
When I compile the program, it runs fine (even this function), but when I try to
access the input from it (which could be just as simple as printing it out), it crashes.
I know that the function is in perfect working order, as I copied the contents of the function from the file over to the main file and the program run as intended, but when it is in the form of a separate function, it doesn't work.
How would I get around this? Thanks for your time!
void MapRead(int ** & a, int & rows, int & cols, int level)
I tried this. The compiler came up with an error after doing this that said "error: expected initialization before 'namespace'". Is there any way around this, or will std:: vector be a better option. I understand a little bit about vectors, but I am not greatly experienced with them. Could someone post me an example of how to use them, please?