UInt to CString and back

This is a discussion on UInt to CString and back within the Windows Programming forums, part of the Platform Specific Boards category; How can I convert from UInt to CString and back and LPTSTR to CString and back?...

  1. #1
    Registered User xlnk's Avatar
    Join Date
    Mar 2002
    Posts
    186

    Question UInt to CString and back

    How can I convert from UInt to CString and back and LPTSTR to CString and back?
    the best things in life are simple.

  2. #2
    Registered User xlnk's Avatar
    Join Date
    Mar 2002
    Posts
    186
    nm i think i got it. Though I get an error when I try to use CString:

    Code:
    error C2065: 'CString' : undeclared identifier
    error C2146: syntax error : missing ';' before identifier 'str'
    error C2065: 'str' : undeclared identifier
    I have windows.h and string.g included.
    Last edited by xlnk; 08-24-2003 at 04:01 PM.
    the best things in life are simple.

  3. #3
    Registered User glUser3f's Avatar
    Join Date
    Aug 2003
    Posts
    345
    from UINT to CString:
    CString str;
    str.Format("%i", 123);

  4. #4
    Registered User xlnk's Avatar
    Join Date
    Mar 2002
    Posts
    186
    Is it even possible to use CString in straight win32 API or is it MFC specific?
    the best things in life are simple.

  5. #5
    Registered User glUser3f's Avatar
    Join Date
    Aug 2003
    Posts
    345
    nope, it's not in Win32 API, you can use it in MFC.

  6. #6
    Registered User xlnk's Avatar
    Join Date
    Mar 2002
    Posts
    186
    Is there an alternative I can use?

    I could use <string> but how can I convert from UINT to string and back?
    the best things in life are simple.

  7. #7
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    The STL has a the sstream header.

    Code:
    #include <iostream>
    #include <sstream>
    
    int main(void) {
      using namespace std;
    
      istringstream from;
      ostringstream to;
      int i;
    
      to << 15;
    
      cout << to.str() << endl;
    
      from = to.str();
      from >> i;
    
      cout << i << endl;
    
      return 0;
    }
    That doesn't have anything to so with MFC however this code should be useful.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Inserting a swf file in a windows application
    By face_master in forum Windows Programming
    Replies: 12
    Last Post: 05-03-2009, 11:29 AM
  2. Writing CObjects with Serialization to CArchive
    By ruben_gerad in forum C++ Programming
    Replies: 0
    Last Post: 11-09-2006, 07:25 AM
  3. Replies: 2
    Last Post: 11-08-2002, 02:22 AM
  4. How to change data format between unsigned char and CString?
    By ooosawaddee3 in forum C++ Programming
    Replies: 1
    Last Post: 11-07-2002, 01:49 PM
  5. CString return value
    By John Bosko in forum C++ Programming
    Replies: 5
    Last Post: 10-05-2002, 04:31 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21