lundi 15 octobre 2018

Convert the string of integer to 2D vector of integers

Given my desired output to be a square output (don't need any spaces between them):

1234
2345
3456
4567

Given the same square of numbers, but each one of them being a string, how can I implement a 2D vector that will take each character of the square and first convert each character into an int and then store into a 2D vector of rows and column to make the exact same square?

I know that a 2D vector needs to be

vector<vector<int>> square_vector;

But I was having trouble taking all of the paired rows and column.

EDIT: If my square is

1234
2345
3456
4567

I want to go through the first row 1234 first. Then within that row, I want to go through each column character 1, 2, 3, 4 and convert each character to an int. After converting, I want to push_back as a row into the 2D vector. After a row is complete, I would like to move on to the next row and perform the same task.

Aucun commentaire:

Enregistrer un commentaire