Results 1 to 6 of 6

Thread: Type Conversion (very easy)

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2001
    Posts
    843

    Type Conversion (very easy)

    humm... how do you convert an int to CString?
    "The difference between mad and genius is the success"

  2. #2
    jim mcnamara
    Guest
    If you are not using unicode the base character for CString.
    is TCHAR, which is based on char.

    You can cast TCHAR from char:

    Code:
    TCHAR *v;
    int i
    char test[20];
    sprintf(test,"%d",i);
    v= (TCHAR) test;

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2001
    Posts
    843
    hi Jim.... How can I put the vaue of and int var to for exampe to a CString var?

    OR.. how can I display the value of an int var in the MessageBox of VC++?

    Thank you for heping me
    "The difference between mad and genius is the success"

  4. #4
    Fanatic Member Wynd's Avatar
    Join Date
    Dec 2000
    Location
    In a bar frequented by colossal death robots
    Posts
    772
    Try this:

    PHP Code:
    #include <iostream>
    #include <cstdlib>
    using namespace std;
    #include <windows.h>

    int main()
    {
        
    int nInput;
        
    char szText[20];

        
    cout << "Enter a number: ";
        
    cin >> nInput;

        
    sprintf(szText"%d"nInput);

        
    MessageBox(NULLszText"Test"MB_OK);

        return 
    0;

    Alcohol & calculus don't mix.
    Never drink & derive.

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    CString str;
    str.Format("Any control string %i you want.", 123);
    TRACE("%s", (LPCTSTR)str);

    will output:
    Any control string 123 you want.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2001
    Posts
    843
    thank you thats exactly what i needed
    "The difference between mad and genius is the success"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width