gpt4 book ai didi

c++ - 在 C++ 中将字符串解析为 double 失败

转载 作者:行者123 更新时间:2023-11-30 01:31:51 26 4
gpt4 key购买 nike

这是一个有趣的问题,我一直在努力弄清楚。我有以下程序:

#include <iostream>
#include <string>
#include <sstream>

using namespace std;

int main(int argc, char *argv[])
{
string s("5");
istringstream stream(s);

double theValue;
stream >> theValue;

cout << theValue << endl;
cout << stream.fail();
}

输出是:

0
1

我不明白为什么会失败。有人可以告诉我我做错了什么吗?

谢谢,

螺旋

编辑:

好吧,抱歉把它变成一个 double post ,但这看起来像是 Xcode 特有的问题。如果我用 g++ 编译它,代码就没有问题。有没有人知道为什么 Xcode 中会发生这种情况,我该如何解决?

最佳答案

您确定这正是您正在构建的内容吗?我按预期得到 50

关于c++ - 在 C++ 中将字符串解析为 double 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2634580/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com