Results 1 to 2 of 2

Thread: Converting data types

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,091
    Hi,

    I was wondering if someone could just give me a quick run down of how you convert datatypes to other datatypes in C++.

    For example, how would I convert an int value to a string value?

    Any help would be appreciated..

    Dan


  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    For the basic types, you can cast between them:
    Code:
    long val;
    int other = 2;
    
    val = (long)other;
    For a string, use:
    Code:
    char buf[40];
    int num = 50;
    int radix = 10; // number base
    
    itoa(num, buf, radix);
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

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