Expression must be a modifiable value

I am creating a 2d vector "grid" in which a multiplication table is printed out.
Does anyone under stand why I am getting "expression must be a modifiable value"
on the line that says "temp.push_back(col) = x * y;"
Thanks!

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
32
33
34
35
#include <iostream>
#include <vector>


using namespace std;


int main()
{
	vector <vector<int>>stuff; 
								

	for (int row = 0,int x = 0; row < 11; row++,x++) //row
	{
		vector <int> temp;
		for (int col = 0,int y = 0; col < 11; col++,y++) //col
		{
			temp.push_back(col) = x * y;
		}

		stuff.push_back(temp);
	}

	for (int row = 0; row < stuff.size(); row++)
	{
		for (int col = 0; col < stuff[row].size(); col++)
		{
			cout << stuff[row][col] << "\t";
		}
		cout << "\n";
	}

	return 0;
}
Last edited on
push_back takes the value to be pushed at the end of the container. You're pushing the index, not the value.

The code should be: temp.push_back(x * y);
Topic archived. No new replies allowed.