Hello. I am currently having a problem reading an input file: It prints an error message stating, "error: invalid operands of types 'std::ifstream()' and 'int' to binary 'operator>>'".
The file with the function is below:
AemRandW.cpp:
AemRandW.h:Code:#include "AemRandW.h" #include <fstream> using namespace std; void MapRead(int level, int d, int e, int mapdt){ ifstream LoadMap(); int dpos, epos, *dposy = &dpos, *eposy = &epos; bool x = 0; if(level == 1){ifstream LoadMap("1.aem");} if(level == 2){ifstream LoadMap("2.aem");} if(level == 3){ifstream LoadMap("3.aem");} if(level == 4){ifstream LoadMap("4.aem");} if(level == 5){ifstream LoadMap("5.aem");} if(level == 6){ifstream LoadMap("6.aem");} if(level == 7){ifstream LoadMap("7.aem");} if(level == 8){ifstream LoadMap("8.aem");} if(level == 9){ifstream LoadMap("9.aem");} if(level == 10){ifstream LoadMap("10.aem");} while(x == 0){ LoadMap >> d >> e; for(dpos = 0; dpos < d; dpos++){ for(epos = 0; epos < e; epos++){ LoadMap >> mapdt[dposy][eposy]; } } x = 1; } }
The files (.aem) are structured so that the first array dimension (x) is at the beginning, followed by the second (y), followed by the individual array elements. An example ("1.aem") is shown below, with dimension 1's value in green, dimension 2's value in blue and the individual elements in red:Code:#ifndef AEMRANDW_H_INCLUDED #define AEMRANDW_H_INCLUDED #include <iostream> using namespace std; void MapRead(int level, int d, int e, int mapdt); #endif // AEMRANDW_H_INCLUDED
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
Could somebody explain how to avoid this problem please?
Thanks for your time (and sorry for the waffle!)



1Likes
LinkBack URL
About LinkBacks




I used to be an adventurer like you... then I took an arrow to the knee.