2016-10-06 104 views
0

我想将值添加到采用int键和char值的映射变量中。该地图将包含字母表中字母的位置以及该位置上的相应字母。出于某种原因,我在for循环中从.insert()部分收到错误。使用for循环创建映射

map<int, char> cipher; 

for (int i = 0; i < 26; i++) 
{ 
    cipher.insert(i, char(97 + i)); 
} 

回答

1

下面是正确的语法使用地图时:

for (int i = 0; i < 26; i++) 
{ 
    cipher[i] = char(97 + i); 
} 

//To use it 
std::cout << cipher[letterindex] << std::endl; 
+0

你也应该阅读下面的答案 – Treycos