Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7672803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:22:10+00:00 2026-05-31T16:22:10+00:00

In the header of C++11, there are three new functions for conversion between number

  • 0

In the header of C++11, there are three new functions for conversion between number and string.

std::string std::to_string(unsigned long long);
std::string std::to_string(long double);
std::string std::to_string(long long);

The first question – why there is only 3 functions? What about simple int or unsigned int, etc.?

The second question – why to_string doesn’t throw exception in following code?

long double x = std::numeric_limits<long double>::quiet_NaN();
std::string i = std::to_string( x ); 
long double c = std::stold( i ); // i = "1.#QNAN"

And the third question – why c equals 1.0 ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T16:22:11+00:00Added an answer on May 31, 2026 at 4:22 pm
    • “As long as it yields the behavior described, do what you please..“

      All intrinsic numeric types can implicitly be converted to either unsigned long long, long double or long long and still hold the precision required, therefore no more overloads are necessary.

      The standard says that the following functions should be defined, though a lib confirming to the standard is free to do “whatever it wants” as long as it yields the same behavior as described.


    • Why should it throw an exception?

      std::numeric_limits<long double>::quiet_NaN(); is a valid value, and std::to_string (T) is described in the standard to yield the same behavior as calling sprintf with the appropriate format-string.

    § 21.5/6                   Numeric conversions

    • string to_string(int val);
    • string to_string(unsigned val);
    • string to_string(long val);
    • string to_string(unsigned long val);
    • string to_string(long long val);
    • string to_string(unsigned long long val);
    • string to_string(float val);
    • string to_string(double val);
    • string to_string(long double val);

      ..

    Returns:

    • Each function returns a string object holding the character
      representation of the value of its argument that would be generated by
      calling sprintf(buf, fmt, val) with a format specifier of “%d“, “%u“,
      “%ld“, “%lu“, “%lld“, “%llu“, “%f“, “%f“, or “%Lf“, respectively,
      where buf designates an internal character buffer of sufficient size.

    • On what compiler is c equal to 1.0?

      The conversion should yield a NaN-value if the value of i is string representation of NaN (not containing any digits).

      If no suitable conversion can be found the function is described to throw invalid_argument.

      MSVC will yield 1.#QNAN when trying to convert std::numeric_limits<long double>::quiet_NaN(); to a std::string.

      When using std::stold it will look for the first none whitespace character, and then use as many digits as found (in this case only 1), therefore c will be equal to 1.0 after the function call.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using a header for a Listview. ListView header has three columns. Say
is there additional header which is presented by openssl before sending the message to
Scenario: One header DIV with three DIV's inside side by side floated left. Problem:
I have the simplest code that I want to separate in three files: Header
I am written a User Control. in the User Control, There are Header and
I understand there is a HTTP response header directive to disable page caching: Cache-Control:no-cache
Is there anything in the header of an HTTP request that would allow me
Is there a way to complex databind to a column's header text? Or is
Is there any way to write a valid header/link/image? Something like <a href=index.html><h1 id=logo>Company
Is there a way in rst to have automatic header numbering ? That is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.