unsigned long long to string conversion

This is a discussion on unsigned long long to string conversion within the C++ Programming forums, part of the General Programming Boards category; hi, in c there is a way of getting a unsigned long long into a char array by using sprintf, ...

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    145

    unsigned long long to string conversion

    hi,

    in c there is a way of getting a unsigned long long into a char array by using sprintf, is there a method in c++ that gets an ull into a string?

    thx

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    stringstream - but I thought you weren't supposed to use C++?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Nov 2005
    Posts
    145
    how do u use it?

    unsigned long long input;
    stringstream ss;
    string s;
    s << input;

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,794
    Code:
    unsigned long long input = 1234ULL;
    stringstream ss;
    string s;
    ss << input;
    ss >> s; // or s = ss.str();
    EDIT:
    Oops, unsigned long long, not unsigned long. Note that (signed/unsigned) long long is non-standard in C++ though available as an extension on some compilers.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,183
    and __int64 on some others.

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,590
    > in c there is a way of getting a unsigned long long into a char array by using sprintf,
    Yes there is, but the conversion format still depends on your OS/Compiler (until everyone supports C99 properly).
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  7. #7
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,663
    Quote Originally Posted by cyberfish View Post
    and __int64 on some others.
    I assume unsigned long long would be unsigned __int64.
    I typically just use the macros from the headers, UINT64 or INT64.
    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. OOP Question DB Access Wrapper Classes
    By digioz in forum C# Programming
    Replies: 2
    Last Post: 09-07-2008, 04:30 PM
  2. Replies: 8
    Last Post: 04-25-2008, 02:45 PM
  3. char string to long conversion
    By rastan in forum C Programming
    Replies: 10
    Last Post: 11-06-2003, 06:28 PM
  4. Something is wrong with this menu...
    By DarkViper in forum Windows Programming
    Replies: 2
    Last Post: 12-14-2002, 10:06 PM
  5. can someone check this out and let me know ?
    By javaz in forum C Programming
    Replies: 5
    Last Post: 01-21-2002, 01:13 PM

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