User Tag List

Results 1 to 7 of 7

Thread: Integer to String in C++

  1. #1
    Clicker Multimedia Fusion 2

    Join Date
    Sep 2006
    Location
    Britain, South Coast
    Posts
    1,030
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Integer to String in C++

    Hi all,

    Is there any feature in the SDK to make it easier to convert an integer to a string? I'm very new to C++, and I've seen a big variety of ways on Google but wondered what's the way you guys would normally do it?

    - Chris

  2. #2
    Clicker Multimedia Fusion 2 DeveloperSWF Export Module

    Join Date
    Jun 2006
    Posts
    6,773
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Re: Integer to String in C++

    Code:
    char Buffer[16];
    itoa(Number, Buffer, 10);
    
    // Buffer is your string!
    Or

    Code:
    char Buffer[16];
    sprintf(Buffer, "%d", Number);
    
    // Buffer is your string!

  3. #3
    Clicker Multimedia Fusion 2

    Join Date
    Sep 2006
    Location
    Britain, South Coast
    Posts
    1,030
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Integer to String in C++

    Woah, quick reply! Thanks!

    Out of curiosity, I have only one object in the frame (my extension), yet when I print out the rhNumberOi, it says there are 2 objects? What's the other one, lol??

  4. #4
    Clicker Multimedia Fusion 2 DeveloperiOS Export ModuleSWF Export Module
    Jaffob's Avatar
    Join Date
    May 2008
    Location
    USA
    Posts
    1,833
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Integer to String in C++

    I don't know, what are you printing the number to?

  5. #5
    Forum Moderator Fusion 2.5 DeveloperiOS Export ModuleSWF Export Module

    Join Date
    Jul 2006
    Location
    USA
    Posts
    461
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Integer to String in C++

    I usually use "stringstream" for most conversions, unless I need every bit of efficiency. They work for most data types using the same syntax. Here's an example:

    int x;
    string s;
    stringstream ss;
    ss << "32"
    ss >> x;

    or

    ss << 7;
    ss >> s
    -Mokhtar M. Khorshid

  6. #6
    Clicker Multimedia Fusion 2
    Retriever2's Avatar
    Join Date
    Jun 2006
    Location
    United States
    Posts
    502
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Integer to String in C++

    Just be careful not to stick it in a tight loop or a function that's called frequently. Constructing stringstreams is expensive.

  7. #7
    Clicker Multimedia Fusion 2 Developer

    Join Date
    Jun 2006
    Location
    Darlington, UK
    Posts
    3,298
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Integer to String in C++

    Technically Jamie's code is C, not C++. Still works in C++ though :P

Similar Threads

  1. How to return integer as 01 rather than 1 in a string?
    By assentec in forum Multimedia Fusion 2 - Technical Support
    Replies: 7
    Last Post: 12th December 2012, 03:52 PM
  2. why always integer value when you set global val.?
    By EasySite in forum Multimedia Fusion 2 - Technical Support
    Replies: 5
    Last Post: 7th July 2010, 04:26 PM
  3. Integer split
    By James in forum Released Extensions
    Replies: 1
    Last Post: 1st August 2007, 04:45 PM
  4. Non-integer scaling
    By BenMo in forum Multimedia Fusion 2 - Technical Support
    Replies: 3
    Last Post: 3rd January 2007, 11:54 PM
  5. Text To Integer
    By aussiedave in forum Multimedia Fusion 2 - Technical Support
    Replies: 5
    Last Post: 8th September 2006, 08:21 AM

Posting Permissions

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