小编Wal*_*ald的帖子

奇怪的std :: map行为

以下测试程序

#include <map>
#include <iostream>

using namespace std;

int main(int argc, char **argv)
{
    map<int,int> a;
    a[1]=a.size();
    for(map<int,int>::const_iterator it=a.begin(); it!=a.end(); ++it)
            cout << "first " << (*it).first << " second " << (*it).second << endl;
}
Run Code Online (Sandbox Code Playgroud)

g++ 4.8.1(Ubuntu 12.04 LTS)上编译时导致不同的输出:

g++ xxx.cpp 
./a.out 
first 1 second 1
Run Code Online (Sandbox Code Playgroud)

在Visual Studio 2012(Windows 7)上(标准Win32控制台应用程序项目):

ConsoleApplication1.exe
first 1 second 0
Run Code Online (Sandbox Code Playgroud)

哪个编译器是对的?难道我做错了什么?

c++ g++ visual-studio-2012

50
推荐指数
3
解决办法
2310
查看次数

标签 统计

c++ ×1

g++ ×1

visual-studio-2012 ×1