CString to char* array


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: CString to char* array

  1. #1
    Join Date
    Oct 2004
    Location
    Baltimore MD
    Posts
    69

    CString to char* array

    Hello,

    In an app that I am writing I need to convert a CString variable to a char* array variable. I know that this is probably very easy but I just can't figure it out...

    -Zak

  2. #2
    Join Date
    Dec 2003
    Posts
    3,366
    CString cs = "text";
    char ch[100];
    sprintf(ch, "%s", cs);

    or cs.GetString() may be what you need?

  3. #3
    Join Date
    Nov 2003
    Posts
    4,118
    I think CString has a conversion operator that automatically converts it to const char*. For example:

    CString blah;
    char mybuf[200];
    strcpy(mybuf, blah); //invoke CString's const char * conversion operator

    There is also a member function (I don't remember its name at the moment but you can check the online help of Visual C++) that returns a char array buffer, perhaps CString::data() or anything of that sort.
    Danny Kalev

  4. #4
    Join Date
    Oct 2004
    Location
    Baltimore MD
    Posts
    69
    Thx guys...

    -Zak

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center