随笔 - 493  文章 - 0  评论 - 97  阅读 - 239万

c++ map的使用--键值对的集合

<div class="cnblogs_Highlighter"><pre class="brush:cpp;gutter:false;">#include <iostream>
#include <map>
 
using namespace std;
 
int main()
{
    map<int, string> m;
    m[0] = "h1";
    m[3] = "what";
    m.insert(pair<int, string>(4, "love you"));
 
    cout<<m[0].c_str()<<endl;
    cout<<m[3].c_str()<<endl;
    cout<<m[4].c_str()<<endl;
    cout<<m[2].c_str()<<endl;   // 会产生一个新的元素,即m[2] = ""
 
 
    cout<<m.size()<<endl;       // 4
 
    for(map<int, string>::iterator it = m.begin(); it != m.end(); it++)
    {
        cout<<it->first<<", "<<it->second.c_str()<<endl;
    }
     
 
    return 0;
}
</pre>
</div>

上面的代码在vc.net2005下没有一个warning,但是在vc6下却有94个warning,不知为何?

posted on   清清飞扬  阅读(11359)  评论(0编辑  收藏  举报
编辑推荐:
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
· PostgreSQL 和 SQL Server 在统计信息维护中的关键差异
阅读排行:
· DeepSeek “源神”启动!「GitHub 热点速览」
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 我与微信审核的“相爱相杀”看个人小程序副业
· C# 集成 DeepSeek 模型实现 AI 私有化(本地部署与 API 调用教程)
· spring官宣接入deepseek,真的太香了~
< 2011年2月 >
30 31 1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 1 2 3 4 5
6 7 8 9 10 11 12

点击右上角即可分享
微信分享提示