-1
#include <iostream>
#include <string>
using namespace std;
int main(){
string x;
x = not false and true;
cout << x << endl;
}
为什么此代码在运行时输出笑脸?这段代码输出笑脸是什么?
#include <iostream>
#include <string>
using namespace std;
int main(){
string x;
x = not false and true;
cout << x << endl;
}
为什么此代码在运行时输出笑脸?这段代码输出笑脸是什么?
代码没有问题。
not false and true
相当于!false && true
即1
。然后您使用std::string::operator=(char)
将值分配给x
。 char
的值为1
显然意味着您的系统上会出现一个笑脸。
有关记录,此代码不会在MSVC 2010上编译,抱怨'不'和'和'不是关键字。 –
@WilliamCustode:为了记录,这是自2008版以来的msvc中的一个bug。可以通过包含定义'not','和'等的3rdparty头部来修复。根据[boost forums list](http ://boost.2283326.n4.nabble.com/the-not-keyword-td3865759.html),'#include'应该修复它。 –
SigTerm
啊,很高兴知道。我尽可能多地假设,但是找不到任何来自MS的消息,声称这是一个已知的错误。如果它是一个标准,你应该参考提及它的标准部分。 –