【发布时间】:2017-10-02 22:23:47
【问题描述】:
我正在尝试使用 std::map 为拉丁字母表中的每个字母分配 int 类型值。当我想创建新的 int 并给它一个等于映射到 word 的 int 的值时,我得到一个错误:
F:\Programming\korki\BRUDNOPIS\main.cpp|14|错误:从 'char' 到 'const key_type& {aka const std::basic_string&}' 的用户定义转换无效 [-fpermissive]|
例子:
#include <iostream>
#include <string>
#include <cstdlib>
#include <map>
using namespace std;
int main()
{
std::map <std::string,int> map;
map["A"] = 1;
int x;
std:: string word = "AAAAAA";
x = map[word[3]];
cout << x;
return 0;
}
我做错了什么?
【问题讨论】:
-
@juanchopanza - 你是对的;但是……我的回答太琐碎了……已删除。
标签: c++ string c++11 dictionary compiler-errors