A Map instance

该博客展示了一段C++代码,定义了一个strmap1类,使用std::map<string, int>存储字符串及其对应的ID。类中包含查找、插入和删除操作的方法。在main函数中对这些方法进行了调用,并输出操作结果,体现了std::map的基本使用。
部署运行你感兴趣的模型镜像
#pragma warning(disable:4786)
//...
#include <map>
#include <string>
//...
#include <iostream>
using namespace std;

class strmap1
{
    typedef std::map<std::string, int> type_map;
    typedef type_map::iterator type_iter;

    type_map    mm;
    type_iter   it;
    int         id;

public:
    strmap1() : it(NULL), id(0)
    {
        //init
        id = 0;
        mm["i"] = ++id;
        mm["you"] = ++id;
        mm["he"] = ++id;
    }

    int find(const char* s)
    {
        cout << "find " << s << endl;
        int ret = 0;
        it = mm.find(s);
        if (mm.end() != it) {
            ret = it->second;
            cout << s << "'s id is " << ret << endl;
        } else {
            cout << "can't find " << s << "'s id" << endl;
        }
        return ret;
    }

    int insert(const char* s)
    {
        cout << "insert " << s << endl;
        int ret = ++id;
        mm.insert(type_map::value_type(s, ret));
        //mm[s] = ret;//ok
        return ret;
    }

    void remove(const char* s)
    {
        cout << "remove " << s << endl;
        mm.erase(s);
    }
};

int main(int argc, char* argv[])
{
    cout << "(strmap1)string map 1(simple use std::map<string, int>)" << endl;
    strmap1 o;

    cout << endl;
    o.find("i");
   
    cout << endl;
    o.find("she");
   
    cout << endl;
    o.find("you");
    o.find("he");

    cout << endl;
    o.insert("she");
    o.remove("you");
    o.remove("he");
   
    cout << endl;
    o.find("you");
    o.find("he");
    o.find("she");
   
    cout << endl;
    cout << "haha~~~now only i and she" << endl;
    return 0;
}

--输出结果--
(strmap1)string map 1(simple use std::map<string, int>)
find i
i's id is 1
find she
can't find she's id
find you
you's id is 2
find he
he's id is 3
insert she
remove you
remove he
find you
can't find you's id
find he
can't find he's id
find she
she's id is 4
haha~~~now only i and she

您可能感兴趣的与本文相关的镜像

ACE-Step

ACE-Step

音乐合成
ACE-Step

ACE-Step是由中国团队阶跃星辰(StepFun)与ACE Studio联手打造的开源音乐生成模型。 它拥有3.5B参数量,支持快速高质量生成、强可控性和易于拓展的特点。 最厉害的是,它可以生成多种语言的歌曲,包括但不限于中文、英文、日文等19种语言

<template> <div class="boxs"> <div id="container" ref="mapContainer"></div> <div class="select_BOX"> <el-button @click="btn">测试1</el-button> <el-button>测试2</el-button> <el-button>测试3</el-button> <el-button>测试4</el-button> </div> </div> </template> <script setup> import { ref, onMounted, onBeforeUnmount } from 'vue' import AMapLoader from '@amap/amap-jsapi-loader' const mapContainer = ref(null) const mapInstance = ref(null) const mapInstance1 = ref(null) onMounted(() => { AMapLoader.load({ key: 'd5bc61d4c44e89a8d2594d658e0f347d', version: '2.0', plugins: [ 'AMap.ElasticMarker', 'AMap.Scale', 'AMap.ToolBar', 'AMap.HawkEye', 'AMap.MapType', 'AMap.Geolocation' ] }).then((AMap) => { mapInstance.value = new AMap.Map(mapContainer.value, { viewMode: '3D', zoom: 12, zooms: [5, 30], center: [118.796624,32.059344] }) mapInstance1.value = new AMap.Circle({ center: [118.796624,32.059344], radius: 1000, //半径 borderWeight: 3, strokeWeight: 2, fillOpacity: 0.4, strokeDasharray: [10, 10], }) mapInstance1.value.setMap(mapInstance.value) mapInstance.value.addControl(new AMap.Scale()) mapInstance.value.addControl(new AMap.ToolBar()) mapInstance.value.addControl(new AMap.HawkEye()) mapInstance.value.addControl(new AMap.MapType()) mapInstance.value.addControl(new AMap.Geolocation()) }).catch(e => { console.error('地图加载失败:', e) }) }) onBeforeUnmount(() => { if (mapInstance.value) { mapInstance.value.destroy() } }) </script> <style scoped lang="scss"> .boxs { box-sizing: border-box; padding: 0px; margin: 0px; } #container { padding: 0px; margin: 0px; width: 100%; height: 900px; } .select_BOX { z-index: 999; position: fixed; top: 20px; left: 10px; height: 500px; width: 300px; // box-shadow: 1px 1px 2px 1px #2087bb; border: 1px solid #2087bb; // border-radius: 2%; .el-button{ margin: 4px 0; width: 100%; } } </style> 别改其他代码,点击测试1交互地图把 mapInstance1.value = new AMap.Circle({ center: [118.796624,32.059344], radius: 1000, //半径 borderWeight: 3, strokeWeight: 2, fillOpacity: 0.4, strokeDasharray: [10, 10], })代码加载测试1上
最新发布
09-20
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值