C++ “访问一个”;项目「;地图

C++ “访问一个”;项目「;地图,c++,map,C++,Map,我想访问我的地图的一个“项目” 但这不起作用: for (unsigned int i=0;i<m_ValidCharacterTranslations.Content().size();i++) { wstring wsFirst = &m_ValidCharacterTranslations.Content()[i]->first; wstring wsSecond = &m_ValidCharacterTranslations.Content()

我想访问我的
地图的一个“项目”

但这不起作用:

for (unsigned int i=0;i<m_ValidCharacterTranslations.Content().size();i++)
{
    wstring wsFirst = &m_ValidCharacterTranslations.Content()[i]->first;
    wstring wsSecond = &m_ValidCharacterTranslations.Content().at(i)->second;
    //do something with these 2 wstrings
}
我的类声明如下:

clsTranslations m_ValidCharacterTranslations;

class clsTranslations : public CBaseStructure
{
private:
    map<wstring,wstring> m_content;
protected:
    virtual void ProcessTxtLine(string line);
public:
    map<wstring,wstring> &Content();
    void LoadTranslations(string file);
};
cltranslations m_有效字符翻译;
类别CLS转换:公共CBASE结构
{
私人:
地图内容;
受保护的:
虚空进程txtline(字符串行);
公众:
地图与内容();
void LoadTranslations(字符串文件);
};
有人能告诉我如何得到这些值吗


我希望遍历映射并使用第一个和第二个 地图的第二环

C++11:

for (auto& kvpair : somemap) {
    cout << kvpair.first << " has value " << kvpair.second << std::endl;
}
for(自动和kvpair:somemap){

您不能访问第一个和第二个地址,而不是值。

您试图做什么?因为您所做的在多个级别上没有意义。
Content
返回一个键类型为
wstring
映射,您尝试访问类型为
unsigned int
的键,并尝试将结果值分配给
map
。请使用
std::map
尝试一段更简单的代码,直到您对其界面感到满意为止。您仍在尝试访问键类型为
wstring
的映射中的
unsigned int
键。此外,
map::at
不会返回kv对,而只返回值。我希望遍历映射并使用地图的第一个和第二个W字符串..它们是如何工作的,这一点很清楚。关于你在做什么,不能说同样的事情,第一个评论中的第一句话(“你想做什么?”)还有待回答。它对我不起作用,告诉我“自动类型无法启动”你有c++11编译器吗?如果没有,试试第二个。我不是VS方面的专家,但也许这会有帮助:把它作为一个注释please@P0W新用户不能对其他用户的问题发表评论。
for (auto& kvpair : somemap) {
    cout << kvpair.first << " has value " << kvpair.second << std::endl;
}
for (map<wstring,wstring>::iterator it = somemap.begin(); it != somemap.end(); it++) {
    cout << it->first << " has value " << it->second << std::endl;
}