map 在BCB 里如何实现? 新手有关问题
map 在BCB 里怎么实现? 新手问题。
声明的时候 字符串str 是小写的 string 声明的。
但是在BCB 里不是大写的 String 声明么
求解 ???(接收数据库返回的信息,用MAP 接收)
map<string,int> m;
map<string,int>::iterator p;
qry1->Close();
qry1->SQL->Clear();
qry1->SQL->Add("select fst,count(*) as cnt from tb_new group by fst");
qry1->Open();
while(!qry1->Eof)
{
String str1=qry1->FieldByName("fst")->AsString;
int x1=qry1->FieldByName("cnt")->AsInteger;
ShowMessage(str1);
string str;
str=str1;
// m.insert(pair<string,int>(str1,x1);
qry1->Next();
}
/* for(p=m.begin();p!=m.end();p++)
{
ShowMessage(p->first);
ShowMessage(p->second);
//cout<<p->first<<" "<<p->second<<endl;
} */
下面个代码可以编译过去。
#include <vcl.h>
#include <iostream>
#include <map>
#include <string>
using namespace std;
#pragma hdrstop
//---------------------------------------
#pragma argsused
int main(int argc, char* argv[])
{
map<string,int> m;
map<string,int>::iterator p;
string str;
str="std";
m.insert(pair<string,int>(str,1));
for(p=m.begin();p!=m.end();p++)
{
cout<<p->first<<" "<<p->second<<endl;
}
system("pause");
return 0;
}
------解决方案--------------------
一个是std::string,一个是bcb的类String
要转化一下
------解决方案--------------------
将String转化为string类型使用,如下
String STR = "superman";
string str = STR.c_str();
声明的时候 字符串str 是小写的 string 声明的。
但是在BCB 里不是大写的 String 声明么
求解 ???(接收数据库返回的信息,用MAP 接收)
map<string,int> m;
map<string,int>::iterator p;
qry1->Close();
qry1->SQL->Clear();
qry1->SQL->Add("select fst,count(*) as cnt from tb_new group by fst");
qry1->Open();
while(!qry1->Eof)
{
String str1=qry1->FieldByName("fst")->AsString;
int x1=qry1->FieldByName("cnt")->AsInteger;
ShowMessage(str1);
string str;
str=str1;
// m.insert(pair<string,int>(str1,x1);
qry1->Next();
}
/* for(p=m.begin();p!=m.end();p++)
{
ShowMessage(p->first);
ShowMessage(p->second);
//cout<<p->first<<" "<<p->second<<endl;
} */
下面个代码可以编译过去。
#include <vcl.h>
#include <iostream>
#include <map>
#include <string>
using namespace std;
#pragma hdrstop
//---------------------------------------
#pragma argsused
int main(int argc, char* argv[])
{
map<string,int> m;
map<string,int>::iterator p;
string str;
str="std";
m.insert(pair<string,int>(str,1));
for(p=m.begin();p!=m.end();p++)
{
cout<<p->first<<" "<<p->second<<endl;
}
system("pause");
return 0;
}
------解决方案--------------------
一个是std::string,一个是bcb的类String
要转化一下
------解决方案--------------------
将String转化为string类型使用,如下
String STR = "superman";
string str = STR.c_str();