CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2004
    Posts
    3

    newbie - how do i set a int var to a char

    Hi,
    Im new to c++ and semi experienced at vb.

    I need to know how to convert a integer type variable for example to a string type (char?) variable Is there some keyword or easy way to do this that im missing?

    My question is, how do I do this in c++?:

    dim newVar as integer = cint(stringVariable)

    or

    dim newVar as String = cStr(numberVariable)

    I need to set a integer variable to a string see? Let me know, thanks.

    -JBD

  2. #2
    Join Date
    May 2002
    Posts
    109
    This is really easy.

    int mynumber = 5;

    char buf[501]; CString str;

    sprintf(buf, "%i", mynumber); str = buf;

    So now it's a CString.

    I hope this helps.

  3. #3
    Join Date
    Apr 2002
    Location
    Australia
    Posts
    54
    Have a look in MSDN at function _itoa:

    _itoa
    Convert an integer to a string.
    char *_itoa( int value, char *string, int radix );
    Alternatively, if you are using CString you can use the Format member function:

    eg:

    Code:
    CString str;
    int i = 1;
    str.Format("%d", i);

  4. #4
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652
    Take a look at the following FAQ...

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

Featured