#include "stdafx.h"
#include <map>
#include <string>
#include <iostream>
using namespace std; #define fn(x) int a##x; //声明一个ax变量 a常量 x变量
#define tn(x) #x //可以直接拼一个字符串 int 可以直接输出 int //可以帮你写一个类
#define cclass(cname,x,y,z) class C##cname\
{\
public:\
x m_##x;\
y m_2##y;\
char m_##z;\
}; /////////////////////////////////////////////////////////////////////////
template <class ContainersType>
void PrintContainersData(ContainersType containers)
{
ContainersType::iterator begin = containers.begin(),
end = containers.end();
for(;begin!=end;begin++)
{
cout<<"Key = "<<begin->first<<"\t"<<"Value = "<<begin->second<<endl;
}
} int _tmain(int argc, _TCHAR* argv[])
{
cout<<"First output :"<<tn(int)<<endl;
cclass(Hero,int,int,heroName); //注意:此处用到了 定义的宏
CHero h1; fn();
a3 = ;
cout<<"Second output a3 = "<<a3<<endl;
/////////////////////////////////////////////////////////////////////////
map<string,float> m;
m["Tom"] = ;
m["Jack"] = ;
m["Jack"] = ; //注意:下面的会将上面的成绩修改 cout<<"Third output : "<<endl;
map<string,float>::iterator it = m.begin();
for(; it!=m.end();it++)
{
cout<<it->first<<" "<<it->second<<endl;
} cout<<"Forth output : "<<endl;
PrintContainersData(m); //m.insert(make_pair("Jack",100)); //注意:如果有相同的 则不可插入
m.insert(map<string,float>::value_type("Jack",)); //int t = m["ww"]; //注意[]:找不到 会自动添加这个名字
cout<<"Fifth output : "<<endl;
map<string,float>::iterator it2 = m.find("ww"); //注意find():找不到 会处理
if(it2==m.end())
cout<<"not find"<<endl; return ;
}

运行结果 如下图:

#define 的一些用法 以及 迭代器的 [] 与 find()函数的区别的更多相关文章

  1. #ifndef#define#endif的用法

    在网上看到了感觉作者总结得很好,作者辛苦了! #ifndef#define#endif的用法 文件中的#ifndef 头件的中的#ifndef,这是一个很关键的东西.比如你有两个C文件,这两个C文件都 ...

  2. #ifndef#define#endif的用法(整理)

    [转] #ifndef#define#endif的用法(整理)    原作者:icwk  文件中的#ifndef 头件的中的#ifndef,这是一个很关键的东西.比如你有两个C文件,这两个C文件都in ...

  3. c/c++头文件中#ifndef/#define/#endif的用法

    想必很多人都看过“头文件中用到的 #ifndef/#define/#endif 来防止该头文件被重复引用”.但是是否能理解“被重复引用”是什么意思?头文件被重复引用了,会产生什么后果?是不是所有的头文 ...

  4. Oracle 变量 之 define variable declare 用法及区别

    Oracle 变量 之 define variable declare 用法及区别 Table of Contents 1. 扯蛋 2. define和accept 3. variable 3.1. ...

  5. STL之--插入迭代器(back_inserter,inserter,front_inserter的区别)

    除了普通迭代器,C++标准模板库还定义了几种特殊的迭代器,分别是插入迭代器.流迭代器.反向迭代器和移动迭代器,定义在<iterator>头文件中,下面主要介绍三种插入迭代器(back_in ...

  6. Python3基础(4)匿名函数、装饰器、生成器、迭代器、内置函数、json&pickle序列化、软件目录开发规范、不同目录间模块调用

    ---------------个人学习笔记--------------- ----------------本文作者吴疆-------------- ------点击此处链接至博客园原文------ 1 ...

  7. CSS 属性 :before && :after的用法,伪类和伪元素的区别

    一::before && :after的用法 :before 如同对伪元素的名称一样,:before 是用来给指定的元素的内容前面插入新的内容.举例说明: .before:before ...

  8. 【转】const的用法,特别是用在函数前面与后面的区别!

    在普通的非 const成员函数中,this的类型是一个指向类类型的 const指针.可以改变this所指向的值,但不能改变 this所保存的地址. 在 const成员函数中,this的类型是一个指向 ...

  9. const的用法,特别是用在函数前面与后面的区别!

    const的用法,特别是用在函数后面 在普通的非 const成员函数中,this的类型是一个指向类类型的 const指针.可以改变this所指向的值,但不能改变 this所保存的地址. 在 const ...

随机推荐

  1. 【POJ 1062】昂贵的聘礼(最短路)

    Dijkstra最短路,每次限制一个等级差,再更新答案. #include <cstdio> #define N 105 #define INF 1e9 int m, n; int p[N ...

  2. C++ Standard-Library Random Numbers

    Extracted from Section 17.4 Random Numbers, C++ Primer 5th. Ed. The random-number library generates ...

  3. Opencv加载和显示图片

    #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include <ios ...

  4. Android:Touch和Click的区别

    http://blog.csdn.net/hufeng882412/article/details/7310142 针对屏幕上的一个View控件,Android如何区分应当触发onTouchEvent ...

  5. Java初学(八)

    一.图解String类创建对象及赋值 面试题: 二.String.StringBuffer.StringBuilder区别 1.String内容不可变,而StringBuffer.StringBuil ...

  6. TFS2008 安装图解(详细版本)(转载)

    由于公司准备上TFS,最近开始学习搭建TFS环境,并为同事讲解TFS的使用,在虚拟 机中搭建测试环境,遇到了很多问题,总结成一篇博客,跟大家交流一下: 我是从微软公司官方网站下载的TFS 2008 1 ...

  7. 如果jsp提交到action为空指针的话

    很严重的一点:表单<form>有没有添加一个method="post",如果表单的这个没有写,肯定是空指针, 哎,被这个坑爹的代码,查了好久,特此记录下

  8. c++实现加密和解密算法以及JNI技术的应用实例

    #include "jiami.h" #include "jni.h" #include "com_test_start_CommonClassLoa ...

  9. powerdesigner设置表主键列为自动增长。

    powerdesigner 版本12.5 创建表就不说了.下面开始介绍设置自动增长列. 1 在表视图的列上创建.双击表视图,打开table properties ———>columens ,双击 ...

  10. linux基本命令(2)-备份压缩命令

    一.tar命令 .解压文件 .tar.gz -C /opt (解压到/opt下) / /opt/tomcat (建立链接文件) 二.zip命令 // 1.把/home目录下面的mydata目录压缩为m ...