不知道该如何叙述这个问题,请看代码:
#include <set>
#include <iostream>
using namespace std;
struct test {
int data[3];
};
int main(void) {
test t1;
set<test> s;
s.insert(t1);
s.begin()->data[0] = 1;//此处赋值报错:read-only variable is not assignable
return 0;
}
应该是set内部的问题吧?
求高人解释,非常感谢...
The elements in the set cannot be changed, they can only be added or deleted. http://www.cplusplus.com/refe...
It seems to mean: Read-only variables cannot be assigned. . .
The iterator of set is read-only and does not allow modification (because the elements are sorted internally in set, changing the value of the elements at will may destroy its ordering);
To change the value of an element, you can only delete the old one first and then insert the new one