const_iterator问题

时间:2011-09-02 02:09:13

标签: visual-c++

我之前从未使用过const_iterator,并且很难进行调试。任何帮助表示赞赏。 Windows 7和VS 2010谢谢。

typedef std::basic_string <unsigned char> ustring;
ustring receivedData(data[i], length);
typedef std::map<string, int> MapMime;
MapMime mymap;

mymap["audio/basic"] = 1;
mymap["audio/x-aiff"] = 2;
mymap["audio/x-wav"] = 3;
mymap["video/mpeg"] = 4;
mymap["video/mpeg-2"] = 5;
mymap["video/quicktime"] = 6;

for (MapMime::const_iterator it = mymap.begin(), itEnd = mymap.end();it !=   itEnd.++it);
{
size_t findPosition = receivedData.find(it->first);
if (findPosition != string::npos)
    {
    // Found a match at position findPosition
    }
    else
    {
    // That MIME type was not found in the data...
    }
}

1 个答案:

答案 0 :(得分:3)

for循环后你有一个额外的分号,你应该删除它。否则,'it'仅在for循环内定义,该循环为空。