Can't assign element of string to char variable

So I'm inputting a string called canvasRow, which inputs fine because I'm able to display the string. However, I made a struct called square with an int row, int column, and char color. The rows and columns are assigned correctly but the color is not. It compiles but when I try to cout canvasRow[wid] or squareInsert.color it shows a Mi with a diamond next to it or the program experiences an error depends on which text file I input.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
void Canvas::input()
{
        
        string title, canvasRow;
        int length, width;
        getline(cin, title);
        canvasTitle = title;
        cin >> length >> width;
        canvasLength = length;
        canvasWidth = width;
        vector<square > canvasRowSq;
        square squareInsert;
        
        for (int len = 0; len <= canvasLength; len++)
        {
                getline(cin, canvasRow);
                //cout << canvasRow;
                for (int wid = 0; wid <= canvasWidth; wid++)
                {
                        //cout << canvasRow[wid];
                        squareInsert.color = canvasRow[wid];
                        squareInsert.row = len;
                        squareInsert.column = wid;
                        //cout << " " << squareInsert.row << " x " << " " << squareInsert.column;
                        canvasRowSq.push_back(squareInsert);
                }
                cout << endl;
                canvasRows.insert(canvasRows.begin(), canvasRowSq);
        }
        
}
Topic archived. No new replies allowed.