I am going to make code of Game of Life and read coordinates from a txt file when I uses stoi function it throws exception
void ReadFromFile() { ifstream read; // handler to read from file string line, xFromFile, yFromFile; // for reading files content
read.open("Board.txt");
if (read.is_open())
{
while (getline(read, line))
{
read.seekg(0); // to get pointer on the start
stringstream obj;
obj >> line; //
getline(obj, xFromFile, ' ');
getline(obj, yFromFile, ' ');
x_cordinate = stoi(xFromFile); // stoi conerts a string to an integer
y_cordinate = stoi(yFromFile);
cout << "x " << x_cordinate << " y " << y_cordinate << endl;
}
}
else
{
cout << "File hasn't found" << endl;
exit(EXIT_FAILURE);
}
}
Aucun commentaire:
Enregistrer un commentaire