DEBUG 错误,,,...进来看下....

huang_555 2011-05-26 04:16:55

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <fstream>
#include <iterator>
#include <ctime>
#include <map>
#include <set>
using namespace std;

int main()
{
set<string> str;
map<string,int> str1;

str.insert("an");
str.insert("is");
str.insert("ok");
str.insert("and");
str.insert("the");

ifstream InFile("2.txt");//输入

ofstream OutFile("12.txt");//输出

if (!OutFile || !InFile)
{
cout<<"错误!!!";
return 0;
}

istream_iterator<string> is(InFile);
istream_iterator<string> eof;

ostream_iterator<string> os(OutFile," ");

vector<string> text;

copy(is,eof,back_inserter(text));

for (vector<string>::iterator it=text.begin();it!=text.end();it++)//遍历
{
if (str.find(*it)!=str.end())//是否在排除中
{
text.erase(it);//是就删除掉它
}
}

copy(text.begin(),text.end(),os);//在写到别的文件里去..

return 0;
}




为什么会弹出debug 错误..  
...全文
56 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
pmars 2011-05-26
  • 打赏
  • 举报
回复
[Quote= 引用 2楼 bdmh 的回复:]
试试
it := text.erase(it);
[/Quote]
为什么是 := ???
it = text.erase(it);
就应该可以了吧!
就想叫yoko 2011-05-26
  • 打赏
  • 举报
回复
还有好方法吗
关注下[Quote=引用 3 楼 qqianqq 的回复:]

for (vector<string>::iterator it=text.begin();it!=text.end();it++)//遍历
{
if (str.find(*it)!=str.end())//是否在排除中
{
text.erase(it);//是就删除掉它
it =text.be……
[/Quote]
QQIANQQ 2011-05-26
  • 打赏
  • 举报
回复
for (vector<string>::iterator it=text.begin();it!=text.end();it++)//遍历
{
if (str.find(*it)!=str.end())//是否在排除中
{
text.erase(it);//是就删除掉它
it =text.begin();//迭代器失效的话你重新让它从begin()开始
}
}

bdmh 2011-05-26
  • 打赏
  • 举报
回复
试试
it := text.erase(it);
ryfdizuo 2011-05-26
  • 打赏
  • 举报
回复
erase以后,迭代器失效。。。

64,670

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧