Thread: How to change data format between unsigned char and CString?

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    68

    Smile How to change data format between unsigned char and CString?

    If I have this below unsigned char* data

    'xxxxxxxx' (assume x is Ascii Character)

    How to change from unsigned char* to CString and how to change back from CString to unsigned char*.

    Do you know how to do that?
    Thank you for your answer.
    Last edited by ooosawaddee3; 11-07-2002 at 02:23 PM.

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Few ways to do it.....here's a few

    Code:
    	TCHAR *buff = "Hello World";
    	MessageBox(buff);
    
    	CString str;
    	str = buff;
    	MessageBox(str);
    
    	TCHAR *buff2 = new TCHAR[str.GetLength()+1];
    	if(buff){
    		_tcscpy(buff2,str);
    		MessageBox(buff2);
    	}
    Dont forget that CString's operator=() will take normal char strings for assignment...

    And its operator LPCTSTR() allows you to use string copy functions

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with CString class and operator+ overloading
    By skanxalot in forum C++ Programming
    Replies: 2
    Last Post: 10-07-2003, 10:23 AM
  2. Converting from CString to char
    By Dual-Catfish in forum Windows Programming
    Replies: 5
    Last Post: 06-09-2003, 02:44 PM
  3. Operater overloading - (const char + CString)
    By auth in forum C++ Programming
    Replies: 14
    Last Post: 10-24-2002, 09:22 AM
  4. Assigning char * to CString Object :: C++
    By kuphryn in forum Windows Programming
    Replies: 6
    Last Post: 05-21-2002, 05:40 PM
  5. CString to char - possible??
    By davebaggott in forum Windows Programming
    Replies: 4
    Last Post: 10-11-2001, 02:10 AM