Cstring, char *, String, _ bstr_t, ctime, datetime convert each other

Source: Internet
Author: User
#include <string>
    
#include <iostream>
Using namespace STD;
Void main (void)
{
Cstring strcstring = "ABC ";
Char strchar [256], * pstr;

Pstr = (lpstr) (lpctstr) strcstring; // cstring ----> char *
Strcpy (strchar, (lpstr) (lpctstr) strcstring); // cstring ----> char []

_ Bstr_t strbstr = pstr; // char * ----> _ bstr_t
Wchar * strwchar = strbstr; // B _str_t ---> Unicode

Strbstr = strwchar;
Pstr = strbstr; // Unicode ----> char *

Strcstring = "10 ";
Int istr = atoi (lpstr) (lpctstr) strcstring); // cstring, char [], char * ------> int
Strcstring. Format ("% d", istr); // int -----> cstring
Sprintf (strchar, "% d", istr); // int -----> char []

Pstr = new char [256]; // string request Space
Strcpy (pstr, "ABC"); // string value assignment
Delete [] pstr; // string release

String strstring = "ABC ";
Pstr = (char *) strstring. c_str (); // string ----> char *

Strcstring = "6:24:37"; // cstring ---> coledatetime
Colevariant vtime (strcstring );
Vtime. changetype (vt_date );
Coledatetime time4 = vtime;



Coledatetime time1 (1977,4, 16,2,); // coledatatime ---> ctime
Systemtime receivime;
Varianttimetosystemtime (time1, & systime );
Ctime TM (systime );

Time_t time2 = TM. gettime (); // ctime ---> time_t
Coledatetime time3 (time2); // time_t ---> coledatetime

// Determine whether the string is of a certain type
Cstring svalue ("123.1 ");
Colevariant vvalue (svalue );

Bool bstrisfloat = (succeeded (variantchangetype (& vvalue, & vvalue, 0, vt_r8) & svalue. Find ('.')! =-1 );
If (bstrisfloat)
{
Afxmessagebox ("Floating Point ");
}
}

 

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.