这个图损坏了hhh

map插入数据异常————C++ 记录一次提交代码异常

本文用于自己整理学习,如有不对,不吝赐教

void func1() {
	map<int, int> a;
	a[0] = 1;
	cout << a[0] << endl;
}

void func2() {
	map<int, int> b;
	//b.insert(1, 1);//Error: you cannot dereference an operand of type '_Iter'
	b.insert({ 1,1 });
	cout << b[1] << endl;
}

func2()函数中有一个被注释的写法是错误:Error: you cannot dereference an operand of type '_Iter'。
一般insert()传参时,参数为一个时,参数类型为值,参数为两个时,参数类型为迭代器。

posted @ 2025-01-24 23:08  cstudy  阅读(23)  评论(0)    收藏  举报