Given a regular text file of:
56789
28385
43285
22354
34255
I am trying to read each string character in the text file and store them in a 2D vector.
First I would like to take each string row. Then I would like to take each character in the row and convert into an int then push_back into the row. Then I'd like to repeat for each line.
When outputting each column and row in my 2D vector, I would like the same exact output of:
56789 //each number an int now instead of a string
28385
43285
22354
34255
My issue is that I try to use i = stoi(j);
which gives the error:
No matching function for call to 'stoi'
I do have the correct #include
to be able to use stoi()
vector<vector<int>> read_file(const string &filename)
{
string file, line; stringstream convert; int int_convert, counter;
vector<vector<int>> dot_vector;
file = filename;
ifstream in_file;
in_file.open(file);
while (getline(in_file, line)) {
counter++; //how many lines in the file
}
char current_char;
while (getline(in_file, line)) {
for (int i = 0; i < counter; i++) {
vector<int> dot_row;
for (int j = 0; j < line.size(); j++) {
current_char = line[j];
i = stoi(j); //this is giving me an error
dot_row.push_back(i);
}
dot_vector.push_back(dot_row);
}
}
in_file.close();
return dot_vector;
}