#include<stdio.h>
#include<stdlib.h>
#include <string>
#include <map>
#include <iostream>
using namespace std;
int main (void)
{
enum Name{AMY,JOHN,JOY};
map<Name, string> nameMap;
nameMap[AMY] = "AMY";
nameMap[JOHN] = "JOHN";
nameMap[JOY] = "JOY";Name salesname=JOHN;
string nameStr = nameMap[salesname];
cout<<nameStr<<endl;}这里的error怎样解决?
C++里怎样用map将枚举类转换到string类
答案:3 悬赏:20 手机版
解决时间 2021-02-21 08:09
- 提问者网友:溺爱和你
- 2021-02-20 16:45
最佳答案
- 五星知识达人网友:西风乍起
- 2021-02-20 17:47
#include<stdio.h>
#include<stdlib.h>
#include <string>
#include <map>
#include <iostream>
using namespace std;typedef enum {
AMY,
JOHN,
JOY
}Name;int main (void)
{map<Name, string> nameMap;
nameMap[AMY] = "AMY";
nameMap[JOHN] = "JOHN";
nameMap[JOY] = "JOY";Name salesname=JOHN;
string nameStr = nameMap[salesname];
cout<<nameStr<<endl;} 会出百现很多警告,不度要管他,直问接运答行就可以了,专我用得是属vc++6.0
#include<stdlib.h>
#include <string>
#include <map>
#include <iostream>
using namespace std;typedef enum {
AMY,
JOHN,
JOY
}Name;int main (void)
{map<Name, string> nameMap;
nameMap[AMY] = "AMY";
nameMap[JOHN] = "JOHN";
nameMap[JOY] = "JOY";Name salesname=JOHN;
string nameStr = nameMap[salesname];
cout<<nameStr<<endl;} 会出百现很多警告,不度要管他,直问接运答行就可以了,专我用得是属vc++6.0
全部回答
- 1楼网友:woshuo
- 2021-02-20 19:18
#include<stdio.h> #include<stdlib.h> #include <string> #include <map> #include <iostream> using namespace std;
typedef enum { amy, john, joy }name;
int main (void) {
map<name, string> namemap; namemap[amy] = "amy"; namemap[john] = "john"; namemap[joy] = "joy";
name salesname=john; string namestr = namemap[salesname]; cout<<namestr<<endl;
}
会出现很多警告,不要管他,直接运行就可以了,我用得是vc++6.0
- 2楼网友:舍身薄凉客
- 2021-02-20 18:30
将百map<Name, string> nameMap;改成度知map<int, string> nameMap; 改后道为专:属#include<stdio.h>
#include<stdlib.h>
#include <string>
#include <map>
#include <iostream>
using namespace std;
int main ()
{
enum Name{AMY,JOHN,JOY};
map<int, string> nameMap;
nameMap[AMY] = "AMY";
nameMap[JOHN] = "JOHN";
nameMap[JOY] = "JOY"; Name salesname=JOHN;
string nameStr = nameMap[salesname];
cout<<nameStr<<endl;
return 0;}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯