字符串解析到双重失败在C ++中 [英] string parsing to double fails in C++
问题描述
#include< iostream>
#include< string>
#include< sstream>
使用namespace std;
int main(int argc,char * argv [])
{
string s(5);
istringstream stream;
double theValue;
stream>>价值;
cout<<< theValue< ENDL;
cout<<< stream.fail();
}
输出是:
0
1
不明白为什么这是失败的。有人可以告诉我我做错了什么?
谢谢,
helixed
编辑:
对不起,把它变成一个双发帖,但这看起来像是Xcode特有的问题。如果我用g ++编译这个代码,代码就没有任何问题。有没有人知道为什么在Xcode中发生这种情况,以及我如何解决它?
也许这是问题你有: stringstream问题
看到接受的答案和其中的链接。苹果讨论链接中的一个例子听起来非常像你所遇到的。
Here's a fun one I've been trying to figure out. I have the following program:
#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();
}
The output is:
0
1
I don't understand why this is failing. Could somebody please tell me what I'm doing wrong?
Thanks,
helixed
EDIT:
Okay, sorry to turn this into a double post, but this looks like a problem specific to Xcode. If I compile this in g++, the code works without a problem. Does anybody have an idea why this is happening in Xcode, and how I could possibly fix it?
Perhaps this is the problem you're having: stringstream question
See the accepted answer and the link therein. An example in the Apple discussion link sounds very much like what you're experiencing.
这篇关于字符串解析到双重失败在C ++中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!