!!!急急急急急急急急急急

popkiler 2003-03-17 10:35:03
有谁能帮我调一下,谢了


#ifndef _mystack_H__
#define _mystack_H__


#include <iostream>
#include <map>
#include <string>
//using namespace std;


typedef map<string,float> stringfloatmap;
typedef map<string,char> stringcharmap;
typedef map<string,string> stringstringmap;

class mystack()
{
private:
stringfloatmap sfmap;
stringcharmap scmap;
stringstringmap ssmap;
stringfloatmap :: iterator pos1;
stringcharmap :: iterator pos2;
stringstringmap :: iterator pos3;
public:
void ADD(string _string,float _float);
void ADD(string _string,char _char);
void ADD(string _string1,string _string2);

int FIN(string _string);
void DELE(string _string);
void ALTER(string _string,float _float);
void ALTER(string _string,char _char);
void ALTER(string _string1,string _string2);
}


void mystack::ADD(string _string,float _float)
{
sfmap[_string]=_float;
}

void mystack::ADD(string _string,char _char)
{
scmap[_string]=_char;
}

void mystack::ADD(string _string1,string _string2)
{
sfmap[_string]=_string;
}

int mystack::FIN(string _string)
{


pos1=sfmap.find(_string);
if(pos1!=sfmap.end())
{
cout<<pos1->first<<":"<<pos1->second<<endl;
}
else
{
pos2=scmap.find(_string);
if(pos2!=scmap.end())
{
cout<<pos2->first<<":"<<pos2->second<<endl;
}
else
{
pos3=ssmap.find(_string);
if(pos13=ssmap.end())
{
cout<<pos3->first<<":"<<pos3->second<<endl;
}
else
{
cout<<"HAVE NOT FINDED!!"<<endl;
return 0;
}
}
}
return 1;


}

void mystack::DELE(string _string)
{
stringfloatmap::iterator pos1;
stringcharmap::iterator pos2;
stringstringmap::iterator pos3;

pos1=sfmap.find(_string);
if(pos1!=sfmap.end())
{
sfmap.erase(pos1);
cout<<"delete completed!!"<<endl;
}
else
{
pos2=scmap.find(_string);
if(pos2!=scmap.end())
{
scmap.erase(pos2);
cout<<"delete completed!!"<<endl;
}
else
{
pos3=ssmap.find(_string);
if(pos13=ssmap.end())
{
ssmap.erase(pos3);
cout<<"delete completed!!"<<endl;
}
else
{
cout<<"HAVE NOT FINDED!!"<<endl;
}
}
}
}

void mystack::ALTER(string _string,float _float)
{
stringfloatmap::iterator pos1;
pos1=sfmap.find(_string);
pos1->second=_float;
cout<<pos1->first<<":""<<pos1->second<<endl;
}

void mystack::ALTER(string _string,char _char)
{
stringcharmap::iterator pos2;
pos2=scmap.find(_string);
pos2->second=_char;
cout<<pos2->first<<":""<<pos2->second<<endl;
}

void mystack::ALTER(string _string1,string _string2)
{
stringstringmap::iterator pos3;
pos3=ssmap.find(_string1);
pos3->second=_string2;
cout<<pos3->first<<":"<<pos3->second<<endl;
}



#endif
...全文
83 12 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
popkiler 2003-03-20
  • 打赏
  • 举报
回复
而且能否对map使用new?
popkiler 2003-03-20
  • 打赏
  • 举报
回复
哦,谢谢了,老哥
有个疑问,iterator可以这样用吗?

pos1=new stringfloatmap :: iterator;
pos2=new stringcharmap :: iterator;
pos3=new stringstringmap :: iterator;
老哥,你的帖子:
语法上可能是正确的,依赖于iterator的具体实现,这部分内容标准没有制定。
然而进一步使用(除了比较操作以外)的结果是没有定义的,这是C++标准。
小弟,想问的是:那我怎么办才行
shornmao 2003-03-20
  • 打赏
  • 举报
回复
class MyStack{}最后缺了一个分号。
编译器已经很聪明的猜出来了,你没有看出来吗?

>j:\脚本程序\jiaoben\mystack.h(51) : error C2628: 'mystack' followed by 'void' is illegal (did you forget a ';'?)
popkiler 2003-03-20
  • 打赏
  • 举报
回复
我的main 文件是:

#include "mystack.h"
//#include <iostream>
//#include <map>
//#include <string>
//using namespace std;

void main()
{
mystack tt;
tt.ADD("jj",12.0);
tt.ALTER("jj",3.0);
tt.FIN("jj");
}
popkiler 2003-03-20
  • 打赏
  • 举报
回复
可是还是有错误

j:\脚本程序\jiaoben\mystack.h(51) : error C2628: 'mystack' followed by 'void' is illegal (did you forget a ';'?)
j:\脚本程序\jiaoben\mystack.h(51) : warning C4786: 'std::map<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::less<std::basic_string<char,std::char_traits<
char>,std::allocator<char> > >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >' : identifier was truncated to '255' characters in the debug information
j:\脚本程序\jiaoben\mystack.h(52) : error C2556: 'class mystack __thiscall mystack::ADD(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,float)' : overloaded function differs only by return type from 'void __th
iscall mystack::ADD(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,float)'
j:\脚本程序\jiaoben\mystack.h(39) : see declaration of 'ADD'
j:\脚本程序\jiaoben\mystack.h(52) : error C2371: 'ADD' : redefinition; different basic types
j:\脚本程序\jiaoben\mystack.h(39) : see declaration of 'ADD'
j:\脚本程序\jiaoben\mystack_main.cpp(11) : error C2668: 'ADD' : ambiguous call to overloaded function
popkiler 2003-03-20
  • 打赏
  • 举报
回复
谢谢了Frank001(Frank) 大哥,我也是刚才改了,代码是:

#ifndef _mystack_H__
#define _mystack_H__


#include <iostream>
#include <map>
#include <string>
using namespace std;


typedef map<string,float> stringfloatmap;
typedef map<string,char> stringcharmap;
typedef map<string,string> stringstringmap;

class mystack
{
private:
stringfloatmap sfmap;
stringcharmap scmap;
stringstringmap ssmap;
stringfloatmap :: iterator pos1;
stringcharmap :: iterator pos2;
stringstringmap :: iterator pos3;


public:
mystack()
{
sfmap=new stringfloatmap;
scmap=new stringcharmap;
ssmap=new stringstringmap;

pos1=new stringfloatmap :: iterator;
pos2=new stringcharmap :: iterator;
pos3=new stringstringmap :: iterator;


}
void ADD(string _string,float _float);
void ADD(string _string,char _char);
void ADD(string _string1,string _string2);

int FIN(string _string);
void DELE(string _string);
void ALTER(string _string,float _float);
void ALTER(string _string,char _char);
void ALTER(string _string1,string _string2);
};


void mystack::ADD(string _string,float _float)
{
sfmap[_string]=_float;
}

void mystack::ADD(string _string,char _char)
{
scmap[_string]=_char;
}

void mystack::ADD(string _string1,string _string2)
{
ssmap[_string1]=_string2;
}

int mystack::FIN(string _string)
{



pos1=sfmap.find(_string);
if(pos1!=sfmap.end())
{
cout<<pos1->first<<":"<<endl;
cout<<pos1->first<<":"<<pos1->second<<endl;
}
else
{
pos2=scmap.find(_string);
if(pos2!=scmap.end())
{
cout<<pos2->first<<":"<<pos2->second<<endl;
}
else
{
pos3=ssmap.find(_string);
if(pos3!=ssmap.end())
{
cout<<pos3->first<<":"<<pos3->second<<endl;
}
else
{
cout<<"HAVE NOT FINDED!!"<<endl;
return 0;
}
}
}
return 1;


}

void mystack::DELE(string _string)
{

pos1=sfmap.find(_string);
if(pos1!=sfmap.end())
{
sfmap.erase(pos1);
cout<<"delete completed!!"<<endl;
}
else
{
pos2=scmap.find(_string);
if(pos2!=scmap.end())
{
scmap.erase(pos2);
cout<<"delete completed!!"<<endl;
}
else
{
pos3=ssmap.find(_string);
if(pos3!=ssmap.end())
{
ssmap.erase(pos3);
cout<<"delete completed!!"<<endl;
}
else
{
cout<<"HAVE NOT FINDED!!"<<endl;
}
}
}
}

void mystack::ALTER(string _string,float _float)
{
pos1=sfmap.find(_string);
pos1->second=_float;
cout<<pos1->first<<":value"<<pos1->second<<endl;
}

void mystack::ALTER(string _string,char _char)
{

pos2=scmap.find(_string);
pos2->second=_char;
cout<<pos2->first<<":value"<<pos2->second<<endl;
}

void mystack::ALTER(string _string1,string _string2)
{

pos3=ssmap.find(_string1);
pos3->second=_string2;

cout<<pos3->first<<":"<<pos3->second<<endl;
}



#endif
Frank001 2003-03-20
  • 打赏
  • 举报
回复
……
void DELE(string _string);
void ALTER(string _string,float _float);
void ALTER(string _string,char _char);
void ALTER(string _string1,string _string2);
}; //少了一个;

--------------------------------------------------------
……
if(pos3==ssmap.end()) //这里应该是 == 吧,而不是 = (程序里好像有两处)
……
popkiler 2003-03-20
  • 打赏
  • 举报
回复
谢谢各位,小弟初学stl,而且写的有些仓促,漏洞百出,不好意思了
现将改进后的代码,放上去。可是还是有5个错误,希望各位再次帮助。

特别感谢:Frank001(Frank) ,zhaohangcom(赵)
我将帖子加分了,而且在其他地方也有这个帖子,想要分的说一声。
我再次贴出代码,也是希望csdn能构成为真正的程序员之家!!!

#ifndef _mystack_H__
#define _mystack_H__


#include <iostream>
#include <map>
#include <string>
using namespace std;


typedef map<string,float> stringfloatmap;
typedef map<string,char> stringcharmap;
typedef map<string,string> stringstringmap;

class mystack
{
private:
stringfloatmap sfmap;
stringcharmap scmap;
stringstringmap ssmap;
stringfloatmap :: iterator pos1;
stringcharmap :: iterator pos2;
stringstringmap :: iterator pos3;


public:
mystack()
{
sfmap=new stringfloatmap;
scmap=new stringcharmap;
ssmap=new stringstringmap;

pos1=new stringfloatmap :: iterator;
pos2=new stringcharmap :: iterator;
pos3=new stringstringmap :: iterator;


}
void ADD(string _string,float _float);
void ADD(string _string,char _char);
void ADD(string _string1,string _string2);

int FIN(string _string);
void DELE(string _string);
void ALTER(string _string,float _float);
void ALTER(string _string,char _char);
void ALTER(string _string1,string _string2);
}


void mystack::ADD(string _string,float _float)
{
sfmap[_string]=_float;
}

void mystack::ADD(string _string,char _char)
{
scmap[_string]=_char;
}

void mystack::ADD(string _string1,string _string2)
{
ssmap[_string1]=_string2;
}

int mystack::FIN(string _string)
{



pos1=sfmap.find(_string);
if(pos1!=sfmap.end())
{
cout<<pos1->first<<":"<<endl;
cout<<pos1->first<<":"<<pos1->second<<endl;
}
else
{
pos2=scmap.find(_string);
if(pos2!=scmap.end())
{
cout<<pos2->first<<":"<<pos2->second<<endl;
}
else
{
pos3=ssmap.find(_string);
if(pos3=ssmap.end())
{
cout<<pos3->first<<":"<<pos3->second<<endl;
}
else
{
cout<<"HAVE NOT FINDED!!"<<endl;
return 0;
}
}
}
return 1;


}

void mystack::DELE(string _string)
{

pos1=sfmap.find(_string);
if(pos1!=sfmap.end())
{
sfmap.erase(pos1);
cout<<"delete completed!!"<<endl;
}
else
{
pos2=scmap.find(_string);
if(pos2!=scmap.end())
{
scmap.erase(pos2);
cout<<"delete completed!!"<<endl;
}
else
{
pos3=ssmap.find(_string);
if(pos3=ssmap.end())
{
ssmap.erase(pos3);
cout<<"delete completed!!"<<endl;
}
else
{
cout<<"HAVE NOT FINDED!!"<<endl;
}
}
}
}

void mystack::ALTER(string _string,float _float)
{
pos1=sfmap.find(_string);
pos1->second=_float;
cout<<pos1->first<<":value"<<pos1->second<<endl;
}

void mystack::ALTER(string _string,char _char)
{

pos2=scmap.find(_string);
pos2->second=_char;
cout<<pos2->first<<":value"<<pos2->second<<endl;
}

void mystack::ALTER(string _string1,string _string2)
{

pos3=ssmap.find(_string1);
pos3->second=_string2;

cout<<pos3->first<<":"<<pos3->second<<endl;
}



#endif
zhaohangcom 2003-03-19
  • 打赏
  • 举报
回复
sorry le
map 的 find() 正确,使我使用错误 ^_^
你写的程序 没有什么大的毛病
DELE 方法声明中不用在定义 迭代器了(类中已经定义了)
反正你好好看看
zhaohangcom 2003-03-19
  • 打赏
  • 举报
回复
都是写小错误,例如:类定义怎么加了"括号"class mystack() *
2)类说明部分结尾加 分号
3)pos 11 pos2 pos3 sh使用时使用混乱
4)我试验了 map de find() 怎么好像不好使(你自己看看)
Frank001 2003-03-19
  • 打赏
  • 举报
回复

#include <iostream>
#include <map>
#include <string>

都改为
#include <iostream.h>
#include <map.h>
#include <string.h>

就可以了。
popkiler 2003-03-19
  • 打赏
  • 举报
回复
mei ren!!

24,860

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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