std :: map在炼金术中被打破?

时间:2010-09-20 23:26:29

标签: c++ alchemy

以下代码测试使用std :: map和std :: string作为键:

#include <stdio.h>
#include <map>
#include <string>
using namespace std;

typedef map<string, int> test_map_t;

int main(int argc, char **argv) {
    test_map_t test_map;

    test_map["test1"]= 1;    
    test_map["test2"]= 2;
    test_map["test3"]= 3;    

    string tmp= "test1";
    printf("%s : %d \n", tmp.c_str(), test_map[tmp]);

    return 0;
}

使用普通gcc编译时,此测试将按预期打印出“test1:1”。但是,当使用炼金术编译时,它将打印“test1:3”(!)。这里出了点问题。

是否有任何解决方法或者我只是卡住了?

3 个答案:

答案 0 :(得分:2)

类字符串在炼金术中被打破。运算符副本(=)中存在错误。地图适用于其他类

答案 1 :(得分:1)

当然看起来像个臭虫。

通常情况下,源代码(标题)是STL发行版的一部分 - 您可以直接查看发生了什么吗?可以将源与GCC版本进行比较。

似乎你有一个铸铁案例,如果得到确认,可以将其带到供应商处进行修复。

答案 2 :(得分:0)

你不应该使用cstdio吗?但是你的代码与gcc版本4.4.2 20091027完美配合,我已经测试过了。是完整的代码还是可能覆盖堆栈的东西。

#include <cstdio>
#include <map>
相关问题