当在Linux下cpp文件包括hash_map或hash_set时。会出现"‘hash_map’ was not declared in this scope"问题。

#include <iostream>
#include <string>
#include <hash_map>
using namespace std; int main(void)
{
hash_map<int, string> hmap; hmap[1] = "hi hdu1";
hmap[2] = "hi hdu2";
hmap[3] = "hi hdu3"; hash_map<int, string>::iterator iter;
iter = hmap.find(2);
if (iter != hmap.end())
{
cout << iter->second << endl;
}
else
{
cout << "not find" << endl;
} return 0;
}

原因:hash_map是声明在__gnu_cxx命名空间的,所以仅仅要在程序中加入using namespace __gnc_cxx就能够了^_^

#include <iostream>
#include <string>
#include <hash_map>
using namespace std;
using namespace __gnu_cxx; int main(void)
{
hash_map<int, string> hmap; hmap[1] = "hi hdu1";
hmap[2] = "hi hdu2";
hmap[3] = "hi hdu3"; hash_map<int, string>::iterator iter;
iter = hmap.find(2);
if (iter != hmap.end())
{
cout << iter->second << endl;
}
else
{
cout << "not find" << endl;
} return 0;
}

Linux包括hash_map和hash_set的not declared问题的更多相关文章

  1. Linux中C++提示‘close’ was not declared

    C++socket编程时关闭socket和epoll时出现‘close’ was not declared,是程序头文件缺失导致的.缺失头文件#include <unistd.h>

  2. Linux系统结构

        Linux系统一般有4个主要部分: 内核.shell.文件系统和应用程序.内核.shell和文件系统一起形成了基本的操作系统结构,它们使得用户可以运行程序.管理文件并使用系统.部分层次结构如图 ...

  3. Linux安装后的系统配置

    第一步: Linux系统安装之后,可以设置系统的日期和时间.给系统添加用户.安装软件.在Red Hat网络中注册机器以及完成其他任务.设置代理将允许用户从一开始就配置环境,从 而使用户能够快速地开始使 ...

  4. Linux 系统结构详解

    Linux 系统结构详解 Linux系统一般有4个主要部分: 内核.shell.文件系统和应用程序.内核.shell和文件系统一起形成了基本的操作系统结构,它们使得用户可以运行程序.管理文件并使用系统 ...

  5. Shell 命令--文件创建、搜索命令--总结自《Linux Shell 脚本攻略》

    (一)文件创建命令 1.touch命令 比如:touch abc命令在本地文件夹中创建了一个名为abc的空文件 2.cp命令 cp命令同意我们把一个文件的内容拷贝到同名或不同名的文件里,复制得到的文件 ...

  6. 初识服务器和Linux

    一.什么是计算机 1.介绍 一说到计算机,我们首先想到的就是电脑,没错,电脑就是计算机,但是计算机不只是电脑. 所谓的电脑就是一种计算机,而计算机其实是:接收使用者输入的指令与资料,经中央处理器的数学 ...

  7. Linux常见操作

    前面的话 本文将详细介绍Linux常见操作 基本概念 Linux严格区分大小写,所有内容以文件形式保存,包括硬件 Linux没有扩展名的概念,不靠扩展名来区分文件类型.但有一些约定俗成的扩展名 压缩包 ...

  8. 一、linux 内核介绍

    参考文档: linux 内核剖析:https://www.ibm.com/developerworks/cn/linux/l-linux-kernel/ 1.1 linux 内核历史 在 20 世纪 ...

  9. Linux 驱动开发

    linux驱动开发总结(一) 基础性总结 1, linux驱动一般分为3大类: * 字符设备 * 块设备 * 网络设备 2, 开发环境构建: * 交叉工具链构建 * NFS和tftp服务器安装 3, ...

随机推荐

  1. Selenium WebDriver- 操作frame中的页面元素

    #encoding=utf-8 import unittest import time from selenium import webdriver from selenium.webdriver i ...

  2. Leetcode33--->Search in Rotated Sorted Array(在旋转数组中找出给定的target值的位置)

    题目: 给定一个旋转数组,但是你不知道旋转位置,在旋转数组中找出给定target值出现的位置:你可以假设在数组中没有重复值出现 举例: (i.e., 0 1 2 4 5 6 7 might becom ...

  3. LibreOJ β Round #4

    A游戏 内存限制:256 MiB时间限制:1000 ms标准输入输出 题目类型:传统评测方式:文本比较 上传者: qmqmqm 提交提交记录统计讨论测试数据   题目描述 qmqmqm和subline ...

  4. xml和pandas结合处理的一个小例子-待完善

    #!/usr/bin/env python3 # -*- coding:utf-8 -*- import pandas import json import xml.etree.ElementTree ...

  5. Spring配置文件中使用ref local与ref bean的区别

    Spring配置文件中使用ref local与ref bean的区别.在ApplicationResources.properties文件中,使用<ref bean>与<ref lo ...

  6. HLG2179 组合(dfs水水更健康)

    组合 Time Limit: 1000 MS Memory Limit: 32768 K Total Submit: 57(38 users) Total Accepted: 43(36 users) ...

  7. 九度oj 题目1482:玛雅人的密码 清华大学机试

    题目描述: 玛雅人有一种密码,如果字符串中出现连续的2012四个数字就能解开密码.给一个长度为N的字符串,(2=<N<=13)该字符串中只含有0,1,2三种数字,问这个字符串要移位几次才能 ...

  8. 我要好offer之 概率题大总结

    1. 利用等概率Rand5生成等概率Rand3 Rand5生成等概率Rand3 这个题目可以扩展为:利用等概率RandM生成等概率RandN (M > N) 这里,我们首先明白一个简单的知识点: ...

  9. <编程精粹:编写高质量C语言代码> 读书笔记

    0.规则<The Elements of Programming Style><The Elements of Style> 1.假想的编译程序(1)使用编译器提供的所有的可选 ...

  10. 【CF1023C】Bracket Subsequence(模拟)

    题意:给定一个正则括号序列 s ,让你在当中选择一个长度正好为 t 的子串,使得 t 恰好也是一个正则括号序列 思路:用栈模拟 #include<cstdio> #include<c ...