请大家帮忙找一个错误,错误的原因在哪里?

jkx01whg 2009-06-19 11:49:43
该程序完成字符串统计,然后输出:

#include<iostream>
#include<map>
//#include<utility>
#include<fstream>
//#include<string>

using namespace std;

int main(void)
{
map<string, int> word_count;
string word;
map<string, int>::iterator num;

ifstream f(".\\54.txt", ios::in | iso::nocreate);

if (!f) //open file fail
{
cerr << "54.txt file not open!" << endl;

exit(1);
}

while (f >> word)
{
//insert element with key equal to word and value 1;
//if word already in word_count, insert does nothing;

pair<map<string, int>::iterator,bool> ret = word_count.insert(make_pair(word, 1));

if (!ret.second)
{
++(ret.first->second);
}

}

num = word_count.begin();

while (num != word_count.end())
{
cout << num->first;
cout << " : " << num->second << endl;

num++;
}


f.close;

return 0;

}

//编译错误:
error:statement cannot resolve address of over loaded function
...全文
91 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
jkx01whg 2009-06-20
  • 打赏
  • 举报
回复
谢谢
Sou2012 2009-06-20
  • 打赏
  • 举报
回复
帮顶!!
jkx01whg 2009-06-20
  • 打赏
  • 举报
回复
是在linux下编译的*.cpp文件
goodname 2009-06-20
  • 打赏
  • 举报
回复
都已经给你了正确的代码了,自己仔细看看。

大概有三处错误
第一应该
#include <string>


2
ios::in | ios::trunc

3

f.close();
jkx01whg 2009-06-19
  • 打赏
  • 举报
回复
是在linux下编译
「已注销」 2009-06-19
  • 打赏
  • 举报
回复
GCC 4.4.1通过!
#include <iostream>
#include <map>
//#include <utility>
#include <fstream>
#include <string>
#include <stdio.h>
#include <stdlib.h>

using namespace std;

int main(void)
{
map <string, int> word_count;
string word;
map <string, int>::iterator num;

ifstream f(".\\54.txt", ios::in | ios::trunc);

if (!f) //open file fail
{
cerr << "54.txt file not open!" << endl;

exit(1);
}

while (f >> word)
{
//insert element with key equal to word and value 1;
//if word already in word_count, insert does nothing;

pair <map <string, int>::iterator, bool> ret = word_count.insert(make_pair(word, 1));

if (!ret.second)
{
++(ret.first->second);
}

}

num = word_count.begin();

while (num != word_count.end())
{
cout << num->first;
cout << " : " << num->second << endl;

num++;
}


f.close();

return 0;

}
kingteng 2009-06-19
  • 打赏
  • 举报
回复
别的我不知道,这个
ifstream f(".\\54.txt", ios::in | iso::nocreate); 是不是有点问题,实在linux么?那怎么会有\\
goodname 2009-06-19
  • 打赏
  • 举报
回复


#include <iostream>
#include <map>
//#include <utility>
#include <fstream>
#include <string>

using namespace std;

int main(void)
{
map <string, int> word_count;
string word;
map <string, int>::iterator num;

ifstream f(".\\54.txt", ios::in |ios::trunc);

if (!f) //open file fail
{
cerr << "54.txt file not open!" << endl;

exit(1);
}

while (f >> word)
{
//insert element with key equal to word and value 1;
//if word already in word_count, insert does nothing;

pair <map <string, int>::iterator,bool> ret = word_count.insert(make_pair(word, 1));

if (!ret.second)
{
++(ret.first->second);
}

}

num = word_count.begin();

while (num != word_count.end())
{
cout << num->first;
cout << " : " << num->second << endl;

num++;
}


f.close();

return 0;

}

65,186

社区成员

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

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