• C++ multiset allow duplicated value


    #include <iostream>
    #include <uuid/uuid.h>
    #include <ctime>
    #include <string>
    #include <sstream>
    #include <unistd.h>
    #include <fstream>
    #include <pthread.h>
    #include <queue>
    #include <set>
    #include <iterator>
    
    using namespace std;
    
    static char *uuidValue = (char *)malloc(40);
    static char *dtValue = (char *)malloc(20); 
    char *getTimeNow();
    
    void multiset18();
    
    int main()
    {
        multiset18();
        return 0;
    }
    
    void multiset18()
    {
        multiset <int, greater <int> > ms;
        int len=100;
        for(int i=0;i<len;i++)
        {
            ms.insert(i*i*i);
        }
    
        cout<<"First"<<endl;
        cout<<"\nSize="<<ms.size()<<endl; 
        multiset <int, greater <int> > :: iterator itr;
        for(itr=ms.begin();itr!=ms.end();itr++)
        {
            cout<<*itr<<"\t";
        }
        
        for(int i=0;i<20;i++)
        {
            ms.insert(i*i*i);
        }
    
        cout<<"\n\nSecond"<<endl;
        cout<<"Size="<<ms.size()<<endl;
        for(itr=ms.begin();itr!=ms.end();itr++)
        {
            cout<<*itr<<"\t";
        }
    
        cout<<"\n\nFinished in multiset20() and now is "<<getTimeNow()<<endl;
        free(uuidValue);
        free(dtValue);
    }
    
    
    char *getTimeNow()
    {
        time_t rawTime = time(NULL);
        struct tm tmInfo = *localtime(&rawTime);
        strftime(dtValue, 20, "%Y%m%d%H%M%S", &tmInfo);
        return dtValue;
    }

    Compile

    g++ -g -std=c++2a -I. h1.cpp -lpthread -o h1  -luuid

    Run ./h1

  • 相关阅读:
    自我介绍
    constructor
    arrow function、function.apply
    for each...in
    类与对象与结构体的区别
    编程语言的发展史
    正则表达式中pw、IDCard和EM匹配
    正则表达式速记
    js中用户名的正则(字符,数字,下划线,减号)
    DOM与document的区别
  • 原文地址:https://www.cnblogs.com/Fred1987/p/15733801.html
Copyright © 2020-2023  润新知