关于vector迭代器的问题,搞得我头大了,求解

zebra_zzh zebra_zzh 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
在VS2013中使用vector迭代器,一到使用到迭代器的地方就出错,求解
// Test.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <vector>
#include <iterator>
#include <iostream>

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
vector<int> test;
test.push_back(1);
test.push_back(2);

vector<int>::iterator ptr = test.begin(); //正常
//int a = *ptr; 出错
//*for (ptr; ptr != test.end(); ptr++) 出错
// cout << *ptr;*/
system("pause");
return 0;
}
错误:
1>------ 已启动生成: 项目: Test, 配置: Debug Win32 ------
1>Test.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) void __cdecl _invalid_parameter(wchar_t const *,wchar_t const *,wchar_t const *,unsigned int,unsigned int)" (__imp_?_invalid_parameter@@YAXPB_W00II@Z),该符号在函数 "public: class std::_Vector_const_iterator<class std::_Vector_val<struct std::_Simple_types<int> > > & __thiscall std::_Vector_const_iterator<class std::_Vector_val<struct std::_Simple_types<int> > >::operator++(void)" (??E?$_Vector_const_iterator@V?$_Vector_val@U?$_Simple_types@H@std@@@std@@@std@@QAEAAV01@XZ) 中被引用
1>D:\VS2013Project\gra\Debug\Test.exe : fatal error LNK1120: 1 个无法解析的外部命令
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========

...全文

相关推荐

详解C++中的vector容器及用迭代器访问vector的方法

使用迭代器iterator可以更方便地解引用和访问成员,当然也包括vector中的元素,本文就来详解C++中的vector容器及用迭代器访问vector的方法,需要的朋友可以参考下

weixin_38616330

vector的earse造成迭代器失效的问题

vector的earse造成迭代器失效的问题

hjt_waves

关于vector迭代器失效的几种情况总结

下面小编就为大家带来一篇关于vector迭代器失效的几种情况总结。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧

weixin_38499950

vector list map 遍历删除制定元素 防止迭代器失效的实例

方法如下所示: // k_control.cpp : 定义控制台应用程序的入口点。 // #include “stdafx.h” #include “stdio.h” #include <vector> #include <map> #include <string> #include <list> using namespace std; int _tmain(int argc, _TCHAR* argv[]) { printf(“run main”); vector<int> vect ; vect.push_back(1); vect.push_back(2); vect.push_ba

weixin_38575118

浅谈c++ stl迭代器失效的问题

之前看《C++ Primier》的时候,也解到在顺序型窗口里insert/erase会涉及到迭代器失效的问题,并没有深究。今天写程序的时候遇到了这个问题。 1 莫名其妙的Erase 最初我的程序是酱紫的,别说话,我知道这样是有问题的,可这样是最直观的想法 int arr[]={0,1,2,3,4,5,6,7,8,9,10};   vector<int> a(arr,arr+sizeof(arr)/sizeof(*arr));for (auto it = a.begin(); it != a.end();++it ){ if ((*it)&1){ a.erase(it);

weixin_38741996
评论 4
收藏 已收藏
分享
返回顶部
zebra_zzh
C++ 语言 65,212 成员 250,513 内容