map 插入 vector

#include <string>   

#include <iostream>   

#include <algorithm>   

#include <map>   

#include <vector>   

using namespace std;   

typedef map<string, string> STRING2STRING;   

typedef std::map<string, vector<string > > STRING2VECTOR;   

int main()
{ std::map<string, string > map_test; map_test.insert(STRING2STRING::value_type("", "test1"));
map_test.insert(STRING2STRING::value_type("", "test5")); map<string, string>::const_iterator map_conitor = map_test.begin();
for(; map_conitor!= map_test.end(); map_conitor++)
{ cout<<map_conitor->first<<" "<<map_conitor->second<<endl;
} map<int, vector<string> > m_map; vector<string> m_vec;
m_vec.resize(); m_vec[] = "aaaaa";
m_vec[] = "bbbbb";
// m_vec.clear();
// cout<<m_vec[0]<<endl; m_map[] = m_vec;
if(m_map[].empty()) { cout<<"not push_back can not assignment"<<endl;} cout<<m_map[][]<<endl; // push_back 方式
vector<string> m_vecPush;
m_vecPush = m_map[];
cout<<"assignment m_vecPush:"<<m_vecPush[] <<endl; map<int, vector<string> > m_mapPush;
m_vecPush.resize(); m_vecPush.push_back("aaaaa");
m_vecPush.push_back("bbbbb"); // m_mapPush[0] = m_vecPush; 与 m_mapPush.insert 等价
m_mapPush.insert(pair<int,vector<string> >(,m_vecPush)); if(m_mapPush[].empty()) { cout<<"push_back can not assignment"<<endl;}
cout<<m_mapPush[][]<<endl; // m_mapPush[dev_id].empty() 与 m_mapPush.find(dev_id) == m_mapPush.end() 类似
if(m_mapPush[].empty()) {
cout<<"m_mapPush empty way not exits"<<endl;
} if(m_mapPush.find() == m_mapPush.end()) {
cout<<"m_mapPush find way not exits"<<endl;
} /////////////////////////// vector 清空元素 ///////////////////////////////
// 清空元素,不回收空间
m_vecPush.clear();
cout<<"clear vector size:"<<m_vecPush.capacity()<<endl;
// 清空元素并释放空间
m_vecPush.clear();
vector<string>().swap(m_vecPush);
cout<<"swap vector size:"<<m_vecPush.capacity()<<endl; }

之前在开发板上使用

m_vec[0] = "aaaaa"; 这种方式,然后用 m_map[0] = m_vec; 发现m_vec赋值不成功。要用m_vec.push_back("aaaa")这种方式才能赋值给map。 但在台式linux上不存在这种情况。

C++ vector 使用笔记的更多相关文章

  1. <<Vector Calculus>>笔记

    现在流行用Exterior Caculus, 所以个人觉得Matthews这本书有点过时了. 想学Vector Calculus的话,推荐<Vector Calculus, Linear Alg ...

  2. C++ std::vector 总结笔记

    Initialization #include<iostream> #include<vector> using namespace std; int main() { vec ...

  3. C++笔记(1)

    C++笔记1文件与流笔记 参考博客: https://blog.csdn.net/kingstar158/article/details/6859379       关闭文件中: 当文件读写操作完成之 ...

  4. C++学习笔记之由文本文件读取数据到vector模板建立的二维数组 并存储为新的文本文件

    阅读本文可首先参考: C++学习笔记之输入.输出和文件 测试数据: /*读取txt文件到二维数组*/ #include <iostream> #include <fstream> ...

  5. Essential C++ 学习笔记02--Array/Vector 与指针

    Essential C++ 1.5-1.6节,3.1节笔记 Array/Vector/指针,难度偏大, 但若学习初期不熟悉基本用法,则难以写出有效代码. 1. 基本概念 Array 是一段连续内存,数 ...

  6. STL源码剖析读书笔记之vector

    STL源码剖析读书笔记之vector 1.vector概述 vector是一种序列式容器,我的理解是vector就像数组.但是数组有一个很大的问题就是当我们分配 一个一定大小的数组的时候,起初也许我们 ...

  7. 小猪猪C++笔记基础篇(四)数组、指针、vector、迭代器

    小猪猪C++笔记基础篇(四) 关键词:数组,Vector. 一.数组与指针 数组相信大家学过C语言或者其他的语言都不陌生,简单的就是同一个变量类型的一组数据.例如:int a[10],意思就是从a开始 ...

  8. Effective STL 学习笔记: 多用 vector & string

    Effective STL 学习笔记: 多用 vector & string 如果可能的话, 尽量避免自己去写动态分配的数组,转而使用 vector 和 string . 原书作者唯一想到的一 ...

  9. STL之vector常用函数笔记

    STL之vector常用函数笔记 学会一些常用的vector就足够去刷acm的题了 ps:for(auto x:b) cout<<x<<" ";是基于范围的 ...

随机推荐

  1. 洛谷P2698 [USACO12MAR]花盆Flowerpot

    P2698 [USACO12MAR]花盆Flowerpot 题目描述 Farmer John has been having trouble making his plants grow, and n ...

  2. TortoiseGit连接gitlab,一直要求输入密码

    问题背景: 公司使用gitlab作为代码管理平台,安装了TortoiseGit之后,使用正常.但是重启电脑之后,再次使用TortoiseGit操作时总是提醒输入gitlab的账号.如下图: 问题原因: ...

  3. Swagger2 配置

    1. 每个请求都需要换取key: @Bean public Docket createRestApi() { //添加head参数start ParameterBuilder appId = new ...

  4. Problem B. Harvest of Apples HDU - 6333(莫队)

    Problem Description There are n apples on a tree, numbered from 1 to n.Count the number of ways to p ...

  5. MT【216】韦达定理

    设$n$为正整数,$a_1,a_2,\cdots,a_n;b_1,b_2,\cdots,b_n;A,B$都是正数, 满足$a_i\le b_i,a_i\le A,i=1,2,\cdots,n$ 且$\ ...

  6. MT【58】反演圆和极线极点和谐统一

    解答:如图 评:1.反演圆及其性质介绍: 评2:此题的源头是1995年全国卷压轴题,这里用极线极点的相关性质也可以处理: 注:用相关点法很容易得到轨迹.

  7. HGOI 20190218 题解

    /* 又是AK局... hjc又双叒叕AK了... Hmmm...我侥幸 */ Problem A card 给出无序序列a[]可以选择一个数插入到合适的位置作为一次操作,至少多少次操作后可以把序列变 ...

  8. luogu1169 棋盘制作 (单调栈)

    先预处理出来从每个位置 以0开始 往右交替最多能放多少格 然后就相当于对每一列做HISTOGRA #include<bits/stdc++.h> #define pa pair<in ...

  9. A1095. Cars on Campus

    Zhejiang University has 6 campuses and a lot of gates. From each gate we can collect the in/out time ...

  10. react中跨域请求天气预报接口数据

    背景故事:同源策略(Same origin policy)是一种约定,它是浏览器最核心也最基本的安全功能, 如果缺少了同源策略,则浏览器的正常功能可能都会受到影响.可以说Web是构建在同源策略基础之上 ...