c++中std::multimap、stringstream

#include "iostream"
#include "map"
#include "utility"
#include "sstream"
#include "vector"
using namespace std;

int main(){

    std::multimap<int,std::string> m;

    std::cout << m.size() << std::endl;

    m.insert({3,"i am3-1"});
    m.insert({7,"i am7-1"});
    m.insert({7,"i am7-2"});
    m.insert({8,"i am8-1"});
    m.insert({8,"i am8-2"});
    std::cout << m.size() << std::endl;

    for (auto it = m.begin(); it != m.end(); it = m.upper_bound(it->first)){
        std::cout <<"key = " << it->first <<std::endl;
        std::pair<std::multimap<int,std::string>::iterator,std::multimap<int,std::string>::iterator> lu = m.equal_range(it->first);
        for (auto i = lu.first; i != lu.second; i++){
            std::cout << i->first << " = " << i->second << std::endl;
        }
    }

    auto it = m.lower_bound(7);
    int num = m.count(7);
    for (int i = 0; i < num; i++,it++){
        std::cout << "i " << i << " " << it->first << " " << it->second << std::endl;
    }

    auto u = m.upper_bound(7);
    std::cout << "u " << u->first << " " << u->second << std::endl;
    


    std::string old(" i am a good man!");
    stringstream io(old);
    std::string s;
    std::vector<string> v;
    while (io >> s){
        v.push_back(s);
    }

    std::cout << " v.size " << v.size() << std::endl;
    for (auto s : v){
        std::cout << " " << s << std::endl;
    }

    return 0;
}

结果:

andrew@DESKTOP-1CLR4DJ /cygdrive/e/study/map
$ g++ map.cpp -std=c++11

andrew@DESKTOP-1CLR4DJ /cygdrive/e/study/map
$ ./a.exe
0
5
key = 3
3 = i am3-1
key = 7
7 = i am7-1
7 = i am7-2
key = 8
8 = i am8-1
8 = i am8-2
i 0 7 i am7-1
i 1 7 i am7-2
u 8 i am8-1
 v.size 5
 i
 am
 a
 good
 man!

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值