0

我想访问我的map<wstring,wstring>.

但这不起作用:

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
}

我在最后一行得到的错误是:

No binary operator accepts the right-handed operand of type 'unsigned int'.

我的班级是这样声明的:

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);
};

有人可以告诉我如何获得这些值吗?

4

2 回答 2

2

我想遍历地图并使用地图的第一个和第二个 wstring。

C++11:

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

预 C++11:

for (map<wstring,wstring>::iterator it = somemap.begin(); it != somemap.end(); it++) {
    cout << it->first << " has value " << it->second << std::endl;
}
于 2013-09-22T18:56:38.667 回答
0

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

于 2013-09-22T18:57:12.093 回答