Me and my friends are quite new in programming but we have decided to increase them by making a game project.
We have gotten up to the point where we want to load data from a file into the objects we use to represent the map.
However we use integers for our data in the objects and the ifstream::getline() returns a string. So we need to convert that string(which is all numerical) to an int.
Cell cellMap[1000]
void LoadCells()
{
ifstream Cellfile;
string line;
int a,b=0;
Cellfile.open ("Cells.txt");
if (Cellfile.fail()) // this checks if it load right?
{
cout << "failed load";
return;
}
else{
while(getline(Cellfile,line))
{
cellMap[b].Setpop(line); // this input needs to be numerical
getline(Cellfile,line); // this skips to the next line, correct?
cellMap[b].Setbuildings(line);//
++b;
}
}
return;
}
the only thing the compiler is complaining about is the fact that the functions Setbuildings() and Setpop() only takes integers.