zoukankan      html  css  js  c++  java
  • std::map

    1.例:

    map<int,string> m_mapTest;
    m_mapTest.insert(make_pair(1,"kong"));
    m_mapTest.insert(make_pair(2,"yang"));
    m_mapTest.insert(make_pair(1,"hello1"));
    m_mapTest.insert(make_pair(3,"hello3"));
    m_mapTest.insert(make_pair(2,"hello2"));

    map<int,string>::iterator it = m_mapTest.begin();
    for(;it!=m_mapTest.end();it++)
    {
    string sTem = (*it).second;
    ::OutputDebugString(sTem.c_str());
    ::OutputDebugString(" ");
    }

    输出结果:

    kong
    yang
    hello3

     

    2.vector和map中的erase方法在linux平台和windows平台下的差异

     std::map<int,float>::iterator itr;

     for(itr = i_f_map.begin(); itr != i_f_map.end(); itr = i_f_map.erase(itr));  // win32可用,linux 不可用

     for(itr = i_f_map.begin(); itr != i_f_map.end(); i_f_map.erase(itr++));     // win32,linux均可用
     linux操作系统下使用itr = map.erase(itr)编译不过去,erase返回值为空。
      

     std::vector<int> vecTestList;

     for(std::vector<int>::iterator it = vecTestList.begin(); it != vecTestList.end(); it = vecTestList.erase(it));  //win32可用,linux可用

     for(std::vector<int>::iterator it = vecTestList.begin(); it != vecTestList.end(); vecTestList.erase(it++));   //win32不可用,linux不可用

     linux操作系统下使用vector.erase(it++);循环删除列表的过程中第一次循环删除没有问题,第二次循环删除会异常。

    3.map<,<> >在linux下需要有一个空格

  • 相关阅读:
    Tomcat性能优化总结
    shell 服务器监控 cpu 和 java 占用 CPU 脚本
    编写shell时,遇到let: not found错误及解决办法
    Studio 3T 破解 mogodb
    nginx/iptables动态IP黑白名单实现方案
    创业公司这两年
    致所有的开发者们
    如何成为一名全栈开发工程师
    谈谈在创业公司的几点感触
    推荐阅读《赢在下班后》
  • 原文地址:https://www.cnblogs.com/justkong/p/4782750.html
Copyright © 2011-2022 走看看