std::map Intro
#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的更多相关文章
- C++ std::map
std::map template < class Key, // map::key_type class T, // map::mapped_type class Compare = less ...
- std::map用法
STL是标准C++系统的一组模板类,使用STL模板类最大的好处就是在各种C++编译器上都通用. 在STL模板类中,用于线性数据存储管理的类主要有vector, list, map 等等.本文主要 ...
- C++ std::map::erase用法及其陷阱
1.引入: STL的map中有一个erase方法用来从一个map中删除制定的节点 eg: map<string,string> mapTest; typedef map<string ...
- std::map
1.例: map<int,string> m_mapTest; m_mapTest.insert(make_pair(1,"kong")); m_mapTest.ins ...
- std::map的clear()没有用?
昨天晚上,我徒弟跑过来讲,他的程序的内存占用居高不下,愿意是std::map的clear()没有效果.于是我让他用erase(begin,end); 试试也不行. 代码如下: void release ...
- std::map的操作:插入、修改、删除和遍历
using namespace std; std::map<int,int> m_map; 1.添加 for(int i=0;i<10;i++) { m_map.insert(mak ...
- 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 ...
- Std::map too few template arguments
在上述的代码中,红色波浪线的部分编译的时候报错: error C2976: 'std::map' : too few template arguments 换成std::map<std::str ...
- 使用std::map和std::list存放数据,消耗内存比实际数据大得多
使用std::map和std::list存放数据,消耗内存比实际数据大得多 场景:项目中需要存储一个结构,如下程序段中TEST_DATA_STRU,结构占24B.但是使用代码中的std::list&l ...
随机推荐
- bootstrap.js 文件使用指南
介绍 使用 Bootstrap v3.3.7 时,需要引入三个脚本文件. https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.m ...
- java获取Excel的导出
import java.io.*; import org.apache.commons.io.FileUtils; import org.apache.poi.hssf.usermodel.HSSFC ...
- Jquery 插件开发——citylinkage(省、市、县城市联动选择)
第一部分:背景 开发源于需求,本次城市联动选择插件算是我写插件的一个特例吧,不是我目前工作需要些的,算是兴趣驱使吧.之前呢,一直想写这个插件,然后错过了一个写这个插件的机会(这个得回顾到很久以前了. ...
- sql 脚本创建索引
之前从没有用SqlServer数据库处理过大数据量的表,都是用Oracle,然后一般为数据量较大的表添加索引或主键都是用plsql工具,今天正好需要为一张保存于SqlServer数据库的千万级数据表增 ...
- UWP&WP8.1图片照片添加水印
水印可以自己自己制作,也可以用代码写. 我这里主要写如何添加到照片上面. UWP和WP8.1添加的方法一样.代码是通用的. UWP和WP8.1没有像WPF和WINFROM中darw这样简便的API可以 ...
- 转载 MySQL创建表的语句 示例
show variables like 'character_set_client';#查询字符集 show databases;#列出所有的服务器上的数据库alter create database ...
- hyperledger fabric 中java chaincode 支持离线打包
联盟链由于其本身的特性,目前应用在一些大型国有企业银行比较多.出于安全考虑,这些企业一般会隔离外网环境.所以在实际生产需求中可能存在需要在一个离线的环境中打包安装chaincode的情况. 本文基于这 ...
- Build SSH for Development on Windows Subsystem for Linux
It seems that Windows Subsystem for Linux (WSL) is getting much more mature than the time when it fi ...
- BA 的职责
Responsibility: 确定系统应用范围:获取实际业务情况(但是并不包含与用户完善实际业务的过程),与用户一起分析实际业务中需要通过软件应用来完成的部分: 备注:是否要与用户一同来分析软件应用 ...
- Python导入命令 import from
一 module通常模块为一个文件,直接使用import来导入就好了.可以作为module的文件类型有".py".".pyo".".pyc" ...