所以我知道如何在C#中完成,而不是C++。我試圖解析giver用戶輸入到一個double(稍後做數學),但我是C++的新手,並且遇到了麻煩。幫幫我?將輸入字符串轉換爲float/double C++
C#
public static class parse
{
public static double StringToInt(string s)
{
double line = 0;
while (!double.TryParse(s, out line))
{
Console.WriteLine("Invalid input.");
Console.WriteLine("[The value you entered was not a number!]");
s = Console.ReadLine();
}
double x = Convert.ToDouble(s);
return x;
}
}
C++ ? ? ? ?
[ATOF](http://www.cplusplus.com/reference/cstdlib/atof/) – yngccc
http://stackoverflow.com/questions/1012571/stdstring-to-float - 或 - 雙 – R3D3vil
不完全相同的問題,但方法是相同的:http://stackoverflow.com/questions/16181630/how-to-check-stdstring-if-its-indeed-an-integer/16181759#16181759 –