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 ...
随机推荐
- 23种计模式之Python实现(史上最全最通俗易懂)内容整改中
第一篇 Python与设计模式:前言 第二篇(23种设计模式) 创建类设计模式(5种) 单例模式.工厂模式.简单工厂模式.抽象工厂模式.建造者模式.原型模式 结构类设计模式(7种) 代理模式.装饰器模 ...
- 抓包工具 Fiddler 使用:弱网络环境模拟限速测试流程
转自:http://www.51testing.com/html/80/n-3726980.html 抓包工具 Fiddler 使用:弱网络环境模拟限速测试流程 发表于:2018-6-06 11: ...
- angular 分页2
http://www.alliedjeep.com/2547.htm AngularJS Code (Users.js) var Users = angular.module('Users', []) ...
- c# sql省市联动
C# sql省市联动 USE [Book] GO ); ); ); ); ); ); ); ); ); ); ); ); ); ); ); ); ); ); ); ); ); ); ); ); ); ...
- Django之博客系统:增加标签
一般在发表博客后会给每个帖子加上一个标签.类似帖子关键字的功能.在这一章中来看下如何给博客添加标签功能(tagging) 添加标签需要集成第三方的Django标签应用来完成这个功能.django-ta ...
- Binder学习笔记(五)—— Parcel是怎么打包数据的?
前文中曾经遇到过Parcel,从命名上知道他负责数据打包.在checkService的请求/响应体系中,Parcel只打包了基本数据类型,如Int32.String16……后面还要用于打包抽象数据类型 ...
- [TJOI2015]线性代数(网络流)
[TJOI2015]线性代数(最大权闭合子图,网络流) 为了提高智商,ZJY开始学习线性代数.她的小伙伴菠萝给她出了这样一个问题:给定一个n*n的矩阵B和一个1×n的矩阵C.求出一个1×n的01矩阵A ...
- Jenkins 相关
手动下载Jenkins plugin 的地址, 下载后的是zip 文件,然后再手动修改为.hpi 文件,然后再手动上传 https://plugins.jenkins.io/
- LUNA16数据集(一)简介
LUNA16,全称Lung Nodule Analysis 16,是16年推出的一个肺部结节检测数据集,旨在作为评估各种CAD(computer aid detection计算机辅助检测系统)的ban ...
- 读经典——《CLR via C#》(Jeffrey Richter著) 笔记_对象的相等性和同一性
[重写Equals注意的事项] 1. Equals 必须是自反的:--x.Equals(x)肯定为 true 2. Equals 必须是对称的:--x.Equals(y)肯定返回与y.Equals(x ...