在C++ 11的標題中,有三個用於在數字和字符串之間轉換的新函數。數字轉換
std::string std::to_string(unsigned long long);
std::string std::to_string(long double);
std::string std::to_string(long long);
第一個問題 - 爲什麼只有3個功能?簡單的int或unsigned int等等呢?
第二個問題 - 爲什麼to_string不會在下面的代碼中拋出異常?
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"
第三個問題 - 爲什麼c等於1.0?
野生猜測,但可能只有那三個存在,因爲較小的整數和浮點類型可以很容易地轉換爲它們而不會丟失信息。 – Collin 2012-03-21 13:01:15