| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1394 人关注过本帖
标题:我的<unordered_map>是不是没有安装好
只看楼主 加入收藏
FollowDream
Rank: 2
等 级:论坛游民
帖 子:33
专家分:14
注 册:2017-1-12
结帖率:33.33%
收藏
已结贴  问题点数:1 回复次数:2 
我的<unordered_map>是不是没有安装好
这是一个很简单的unordered_map写成的字典,就是把一个vector里的元素编号然后两两求和:

程序代码:
# include <iostream>
# include <cstdio>
# include <vector>
# include <unordered_map>
using namespace std;
class Sum2
    {
    public:
    vector<int> Sum_2(vector<int> &num, int target)
        {
        unordered_map<int, int> mapping;
        vector<int> Sum2_array;
        for (int i = 0; i < num.size(); i++)
            mapping[num[i]] = i;
        for (int i = 0; i < num.size(); i++)
            {
            const int gap = target - num[i];
            if (mapping.find(gap) != mapping.end() && mapping[gap] > i)
                {
                Sum2_array.push_back(i + 1);
                Sum2_array.push_back(mapping[gap] + 1);
                break;
                }
            }
        return Sum2_array;
        }
    };
int main()
    {
    Sum2 class_s2;
    return 0;
    }


代码应该是对的,但是运行起来报错:
In file included from /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/unordered_map:35,
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/c++0x_warning.h:31:2:

error: #error This file requires compiler and library support for the upcoming ISO C++ standard, C++0x. This support is currently experimental, and must be enabled with the -std=c++0x or -std=gnu++0x compiler options.

我的<unordered_map>是不是没有安装好?还是我的编译器gcc或者g++有问题?

谢谢!
搜索更多相关主题的帖子: 元素 
2017-01-13 18:50
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9007
专家分:53942
注 册:2011-1-18
收藏
得分:1 
error中说得很明白了呀
另外,你的gcc版本也太低了,最新的是6.3
2017-01-14 18:13
FollowDream
Rank: 2
等 级:论坛游民
帖 子:33
专家分:14
注 册:2017-1-12
收藏
得分:0 
回复 2楼 rjsp
已经解决了。谢谢!
2017-01-17 18:29
快速回复:我的<unordered_map>是不是没有安装好
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018133 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved