Functions of C + + common gadgets

Source: Internet
Author: User
Tags sprintf
Take the current date string getcurdate () {time_t nowtime;    Time (&nowtime);	
	Take the current time value struct TM *tptr;

	Tptr = LocalTime (&nowtime);
	Char datestamp[32];
        
	ace_os::sprintf (Datestamp, "%04d%02d%02d", tptr->tm_year+1900, Tptr->tm_mon+1,tptr->tm_mday);
return datestamp;
	//Get current time string Getcurtime () {time_t nowtime;   
	Time (&nowtime);	
	struct TM *tptr;	

	Tptr = LocalTime (&nowtime);
    Char timestamp[15];
	memset (TimeStamp, 0x00, 15);
		
	ace_os::sprintf (TimeStamp, "%02d%02d%02d", tptr->tm_hour,tptr->tm_min,tptr->tm_sec);
return timeStamp;
    //int-type string string inttostring (int value) {char tmpstring[15];
    memset (tmpstring, 0x00, 15);
    sprintf (tmpstring, "%d", value);
return tmpstring;
///To process the string as lowercase. void ToLower (String &strtmp) {for (unsigned int i = 0; i < strtmp.length (); i++) {Strtmp[i] = Tol
    Ower (Strtmp[i]);
} return;
///flag the string into ... according to the separator token. int GetItem (string &msg, Char flag, VECTOR&LT;string> &line) {try {if (line.size ()!= 0) {line.clear ();
        } if (msg.length () = = 0) {return 0;

        } Char *tmpmsg = &msg[0];
        int begin = 0;
        int end = 0;
        string tmp;
                for (unsigned int i = 0; i < msg.length (); i + +) {if (tmpmsg[i] = = Flag) {
            end = i;
            else {continue; } if ((End-begin) > 0) {tmp = string (&tmpmsg[begin], end-be
            gin);
            else {tmp = "";               
            begin = End+1;
         
        Line.push_back (TMP); } if ((Msg.length ()-begin) > 0) {tmp = string (&tmpmsg[begin), Msg.length (
            )-begin);
  Line.push_back (TMP);      catch (...)
        {Ace_debug (_info ace_text ("GetItem execpaction:[%s].\n"), Msg.c_str ());
    return-1;
return 0;
////outputs the contents of the vector. void Dispvector (const vector<string> &vectmp) {if (vectmp.size () = = 0) {ace_debug (_info ace_
        TEXT ("Vector is null\n"));        
    Return for (unsigned int i = 0; i < vectmp.size (); i++) {Ace_debug (_info ace_text ("[%25s]\n"),        
    Vectmp[i].c_str ()));
} return;
        ////returns num string strings Laststr (string &from, int num) {if (From.length () <= (unsigned int) num) {
    return from;
    else {return from.substr (From.length ()-num, num);
        } string Leftfullchar (string &from, int count, char flag) {if (From.length () > (unsigned int) count) {
    return from;
    int fullcount = (int) from.length ()-count;
    String strtmp (Fullcount, flag); Strtmp + = from;
return strtmp;
        String Rightfullchar (string &from, int count, char flag) {if (From.length () > (unsigned int) count) {
    return from;
    int fullcount = (int) from.length ()-count;
    String strtmp (Fullcount, flag);
return from+strtmp; }

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.