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

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
...全文
189 8 打赏 收藏 举报
写回复
用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;

}
内容概要:本文研究了基于粒子群算法的风电-水电(抽水蓄能)联合优化调度问题,旨在通过智能优化算法实现新能源与储能系统的协同调度,提升电力系统运行效率与稳定性。研究采用粒子群优化(PSO)算法对风电和抽水蓄能电站的出力进行联合优化,以最小化系统运行成本、减少弃风弃电、提高可再生能源消纳能力为目标,构建了包含风电出力不确定性、水电站水量平衡、抽水蓄能机组运行约束在内的多目标优化模型,并通过Matlab编程实现算法求解与仿真验证。文中详细探讨了算法参数设置、收敛性分析及优化结果的合理性,展示了该方法在实际电力系统调度中的应用潜力与工程价值。; 适合人群:具备一定电力系统基础知识和Matlab编程能力的研究生、科研人员及从事新能源调度、智能优化算法应用的工程技术人员。; 使用场景及目标:①应用于含大规模风电接入的电力系统中,实现风电与抽水蓄能的协调调度;②为电力系统经济调度、可再生能源消纳、储能优化配置等研究提供算法支持与仿真案例;③作为智能优化算法在能源系统中应用的教学与研究参考资料。; 阅读建议:读者应结合Matlab代码与文中模型描述,理解算法实现细节,建议在学习过程中动手调试代码,尝试修改目标函数或约束条件以观察优化结果变化,从而深入掌握粒子群算法在能源调度中的应用方法。

65,213

社区成员

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

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