Convert uint16_t to std::string?

This is a discussion on Convert uint16_t to std::string? within the C++ Programming forums, part of the General Programming Boards category; Hi there, what is the best way to convert uint16_t variable into std::string? Could you please show this with a ...

  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    2

    Convert uint16_t to std::string?

    Hi there,

    what is the best way to convert uint16_t variable into std::string? Could you please show this with a code example? Thank you!

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Use << to "print" the integer into a stringstream. Stringstreams convert to strings using the .str() function.

  3. #3
    Registered User
    Join Date
    Jul 2008
    Posts
    2
    worked great, thanks!

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,897
    Another way:
    boost::lexical_cast<std::string>(my_integer);
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 13
    Last Post: 12-14-2007, 03:34 PM
  2. What is the easies way to convert int to std::string?
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 12-04-2007, 02:15 AM
  3. std::string: Has my compiler gone nuts??
    By Andruu75 in forum C++ Programming
    Replies: 9
    Last Post: 09-28-2007, 05:02 AM
  4. Debugging help
    By cuddlez.ini in forum C++ Programming
    Replies: 3
    Last Post: 10-24-2004, 08:08 PM
  5. DLL and std::string woes!
    By Magos in forum C++ Programming
    Replies: 7
    Last Post: 09-08-2004, 01:34 PM

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