It seems, your question isn't really about opening the file and dealing with potential errors there. So, this concentrates on the actual loop. You didn't quite specify the format of your file, though but it seems you get something which contains curlies and separate integers by commas. It is unclear whether each row is on its own line or if it may be split across multiple lines (if the latter; I'd read the entire file, do the transformations below and distribute the result then). I'm assuming each row is on its own line:
std::string line;
for (int row(0); row != rows; ++row) {
if (!std::getline(myfile, line)) {
std::cout << "failed to read all rows!\n";
return false;
}
// remove curlies; spaces don't matter
line.erase(std::remove_if(line.begin(), line.end(),
[](char c){ return c == '{' || c == '}'; }));
std::replace(line.begin(), line.end(), ',', ' ');
std::istringstream in(line);
for (int col(0); col != cols; ++col) {
if (!(in >> map[row][col]) {
std::cout << "failed to read all columns in row " << row << "\n";
return false;
}
}
}
The code first removes the junk from the lines, then replaces commas by spaces as these are neat separators for integers anyway, and then just reads the cells.