关于hash_map的使用

tingtianfeng 2007-10-25 05:03:02
我想在BCB下用hash_map来实现一个翻译的功能,写了如下的程序:

#include <vcl.h>
#include <map>
#include "stlport\hash_map"
using namespace std;

#pragma hdrstop


typedef hash_map<String, String > Months;
typedef pair<String, String> String_Pair;
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Months monthdays;

monthdays.insert(String_Pair("jan", "janvier"));
monthdays.insert(String_Pair("fev", "febrery"));

// Go through all the items in the list
Months::iterator mon;
AnsiString s;
for (mon = monthdays.begin(); mon != monthdays.end(); mon++)
{
s = (*mon).first + " est " + (*mon).second;
ListBox1->Items->Add(s);
}
}
//---------------------------------------------------------------------------

编译的时候老是通不过,请各位帮忙看一下,有什么办法解决。
...全文
386 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
fjye 2007-10-26
  • 打赏
  • 举报
回复
用我的方法修改在BCB6+win2000是通过的,英文版
tingtianfeng 2007-10-26
  • 打赏
  • 举报
回复
郁闷,没天理了。
全世界用那么多语言干吗。
全整汉语多好,省得各种语言之间换来换去,老是出现编译不通过的情况
tingtianfeng 2007-10-25
  • 打赏
  • 举报
回复
难道是因为我的版本太低?我用的是BCB6
  • 打赏
  • 举报
回复
不会吧用控制台程序,那我给你的代码编译
我再bcb2007下通过的
tingtianfeng 2007-10-25
  • 打赏
  • 举报
回复
Appel d 'une non fonction
tingtianfeng 2007-10-25
  • 打赏
  • 举报
回复
还是不行啊,[C++ erreur] _hashtable.h(553):E2314 Appek d'une non fonction (我用的是法语版BCB)
  • 打赏
  • 举报
回复
难道标准C++库里面的东西不属于BCB么?不能用么?
fjye 2007-10-25
  • 打赏
  • 举报
回复
加一个
#include <string>

然后循环里面改成

s = AnsiString((*mon).first.begin()) + " est " + AnsiString((*mon).second.begin());
ListBox1->Items->Add(s);

就可以了
tingtianfeng 2007-10-25
  • 打赏
  • 举报
回复
我要用BCB啊。
  • 打赏
  • 举报
回复
都用标准库的东西吧
#include <vcl.h>
#include<hash_map>
#include<string>
#pragma hdrstop

//---------------------------------------------------------------------------

#pragma argsused
using namespace std;

typedef hash_map <std::string, std::string > Months;
typedef pair <const std::string, std::string > String_Pair;

int main(int argc, char* argv[])
{
Months monthdays;

monthdays.insert(String_Pair("jan", "janvier"));
monthdays.insert(String_Pair("fev", "febrery"));

// Go through all the items in the list
Months::iterator mon=monthdays.begin();
string s;
for (; mon != monthdays.end(); ++mon)
{
s = (*mon).first + " est " + (*mon).second;
}

return 0;
}

13,870

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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