乡亲!我一直在努力解决这个问题,到目前为止我还没有找到任何解决方案.
在下面的代码中,我使用数字初始化一个字符串.然后我使用std :: istringstream将测试字符串内容加载到double中.然后我提出两个变量.
#include <string>
#include <sstream>
#include <iostream>
std::istringstream instr;
void main()
{
using std::cout;
using std::endl;
using std::string;
string test = "888.4834966";
instr.str(test);
double number;
instr >> number;
cout << "String test:\t" << test << endl;
cout << "Double number:\t" << number << endl << endl;
system("pause");
}
Run Code Online (Sandbox Code Playgroud)
当我运行.exe时,它看起来像这样:
字符串测试:888.4834966
双号888.483
按任意键继续...
字符串有更多的数字,看起来像std :: istringstream只加载了6中的10个.如何将所有字符串加载到double变量中?