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

 

 

posted @ 2021-12-26 19:35  FredGrit  阅读(23)  评论(0编辑  收藏  举报