#include <queue>
#include <map>
#include <iostream>
#include <string.h>

class TestU {
public:
TestU(char *);
~TestU();
char *getData();
private:
char *data;
};

TestU::TestU(char *d)
{
if(d) {
int len = strlen(d);
data = new char[len + 1];
strcpy(data, d);
}
}

TestU::~TestU()
{
if(data) {
delete [] data;
}
}

char *TestU::getData()
{
return data;
}

int main(int argc, char **argv)
{
std::queue<TestU>qu;
std::queue<TestU *>q;
std::map<int, TestU *>m;

for(int i = 0; i < 10; i++) {
char str[1024];
sprintf(str, "I am %d", i);
TestU *a = new TestU(str);
TestU *b = new TestU(str);
TestU *c = new TestU(str);
q.push(a);
qu.push(*b);
m[i] = c;
}

while(! q.empty()) {
TestU *a = q.front();
printf("a = [%s]\n", a->getData());
q.pop();
printf("a000 = [%s]\n", a->getData());
delete a;
}

while(! qu.empty()) {
TestU& a = qu.front();
printf("au = [%s]\n", a.getData());
qu.pop();

// printf("au111 = [%s]\n", a.getData());
}

while(! m.empty()) {
TestU *u = m.begin()->second;
printf("m = [%s]\n", u->getData());
m.erase(m.begin());
printf("mm = [%s]\n", u->getData());
delete u;
}

return 0;
}

DEPS=
EXEC=test.x

SRCS=$(wildcard *.c *.cpp)
#SRCS1=$(filter-out dec.c, $(SRCS))
#FNAMES1=$(notdir $(SRCS1))
OBJS=$(patsubst %.c,%.o,$(SRCS))

#CFLAGS += -g -Wall -Wno-unused-result -std=c++11 -std=gnu++11 -fpic -fPIC -D_LARGEFILE64_SOURCE -DUSE_IMPORT_EXPORT
CFLAGS += -g -Wall -Wno-unused-result -std=c++11 -std=gnu++11 -fpic -fPIC -D_LARGEFILE64_SOURCE -DUSE_IMPORT_EXPORT

CFLAGS += -I./include
LDFLAGS += -pthread

%.o: %.c
$(CC) $(CFLAGS) -c -o $@ $<

%.o:%.cpp
$(CXX) $(CFLAGS) -c -o $@ $<

$(EXEC): $(DEPS) $(OBJS)
$(CXX) $(CFLAGS) -o $@ $(OBJS) $(LDFLAGS)

#ifdef STRIP
# $(STRIP) $@
#endif

all: $(EXEC)

clean:
rm -f *.o $(EXEC)

std::map Intro的更多相关文章

  1. C++ std::map

    std::map template < class Key, // map::key_type class T, // map::mapped_type class Compare = less ...

  2. std::map用法

    STL是标准C++系统的一组模板类,使用STL模板类最大的好处就是在各种C++编译器上都通用.    在STL模板类中,用于线性数据存储管理的类主要有vector, list, map 等等.本文主要 ...

  3. C++ std::map::erase用法及其陷阱

    1.引入: STL的map中有一个erase方法用来从一个map中删除制定的节点 eg: map<string,string> mapTest; typedef map<string ...

  4. std::map

    1.例: map<int,string> m_mapTest; m_mapTest.insert(make_pair(1,"kong")); m_mapTest.ins ...

  5. std::map的clear()没有用?

    昨天晚上,我徒弟跑过来讲,他的程序的内存占用居高不下,愿意是std::map的clear()没有效果.于是我让他用erase(begin,end); 试试也不行. 代码如下: void release ...

  6. std::map的操作:插入、修改、删除和遍历

    using namespace std; std::map<int,int> m_map; 1.添加 for(int i=0;i<10;i++) { m_map.insert(mak ...

  7. Using std::map with a custom class key

    From: https://www.walletfox.com/course/mapwithcustomclasskey.php If you have ever tried to use a cus ...

  8. Std::map too few template arguments

    在上述的代码中,红色波浪线的部分编译的时候报错: error C2976: 'std::map' : too few template arguments 换成std::map<std::str ...

  9. 使用std::map和std::list存放数据,消耗内存比实际数据大得多

    使用std::map和std::list存放数据,消耗内存比实际数据大得多 场景:项目中需要存储一个结构,如下程序段中TEST_DATA_STRU,结构占24B.但是使用代码中的std::list&l ...

随机推荐

  1. 使用Maven搭建SSM框架(Eclipse)

    今天学习一下使用Maven搭建SSM框架,以前都是用别人配置好的框架写代码,今天试试自己配置一下SSM框架. 这里我的参数是Windows7 64位,tomcat9,eclipse-jee-neon- ...

  2. php数据连接

    <?php header("Content-type: text/html;charset=utf-8");//设置编码格式为UTF-8 error_reporting(E_ ...

  3. C#检测系统是否激活[转自StackOverFlow]

    using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServi ...

  4. 在GridView控件FooterTemplate内添加记录 Ver3

    重构此篇<在GridView控件FooterTemplate内添加记录 Ver2> http://www.cnblogs.com/insus/p/3270644.html 这有些缺陷,怎样 ...

  5. Data Base 常用数据库之top/limit/rownum用法

    常用数据库之top/limit/rownum用法 一.常用数据库: sql server: select top 10 from users where status=1 mysql: select ...

  6. Lucene 全文检索 Lucene的使用

    Lucene  全文检索  Lucene的使用 一.简介: 参考百度百科: http://baike.baidu.com/link?url=eBcEVuUL3TbUivRvtgRnMr1s44nTE7 ...

  7. HttpRunnerManager接口自动化测试框架测试报告页面优化

    在测试报告生成结果页面,点击左上角的图标不能快速返回到首页.在大神的指点下,要改一个跳转链接,如下图: 修改路径如下: 修改的字段:把<a href="#!" class=& ...

  8. Python3中开发目录的引用

    Python3中开发目录的引用 import os,sys BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) ...

  9. 对接极光IM之修改头像

    因为项目中使用了极光IM,在对接极光的时候,发现了如果想要在改变自己个人中心的头像同时改变极光IM的头像,就必须要将本地磁盘的文件上传到极光服务器,根据反馈的media_id来进行修改头像. 但是因为 ...

  10. Hyperledger Fabric java chaincode 编译部署(1.4V)

    前提条件: 构建好了一个拥有四个peer 一个Order 的1.4版本的Fabric网络. 证书通过Cryptogen生成,没有使用CA服务. 开启TLS. 网络中的peer都加入了一个 名为mych ...