wxWidget 类型转换(wxString, wxdatatime)

samsung_transformer 在C++里常用类型转换感觉很杂,不好用;跟C#没得比:可以强类型转换,还有convert通用的转换,非常方便的说。刚用wxwidget时类型转换也是一头大,了解后发现要比简洁好用多,接口也容易记住。下面上wxWidget常用类型转换:

一、与其他类型转换

    1.1 int  to :     str = ::Format(wxT("%i"),myInt);

    1.2    to int :     int i;  i = wxAtoi(str);

    1.3    string to :     std::string stlString = "sdfas"; mystr(stlString .c_str(),wxConvUTF8);

1.4   to string:    

        mystring(wxT("HelloWorld"));        std::string stlstring = std::string(mystring.mb_str()); 

1.5  char* to :      char* chars = "Hello world";    mystring(chars, wxConvUTF8); 

1.6   to  char*:   char* cs = str.mb_str(wxConvUTF8); 

1.7    char[] to :           char chars[34] = "sefasd";    mystring(chars, wxConvUTF8); 

1.8  to char[]:     mystring(wxT("HelloWorld"));char cstring[1024];strcpy(cstring, (const char*)mystring.mb_str(wxConvUTF8));

 

二、wxdatetime 与转换

2.1  wxdatetime to :wxDateTime dt = CalendarCtrl1->GetDate(); msg = dt.Format(wxT("%Y-%m-%d"),wxDateTime::A_EST);

2.2 to wxdatetime:   char* ca = "2008-09-03";wxDateTime dt;dt.ParseDate(ca);时间格式化参考:http://www.cplusplus.com/reference/clibrary/ctime/strftime.html

 

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/puny/archive/2008/09/04/2882546.aspx

Share and Enjoy:
  • Print this article!
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • LinkedIn
  • Live
  • MySpace
  • RSS
  • Slashdot
  • Technorati
  • TwitThis

Related posts:

  1. wxWidget Layout Algorithm Demo - BoxPlanner
  2. wxWidgets Programming: Sizer, Frame and Panel
  3. 指针与引用的比较
  4. CodeLite to CodeInsight task 1: Internationalization

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Contact us

Admin: Bryan Wu