请仔细检查下面的代码,它只是一个函数的一部分
void RepeatWord(){
system("cls");
string word = NULL;
string newword = NULL;
int repeats = 0;
while(true){
if(word == NULL){
cout<<"Currently no word is stored..";
cout<<"\n\nPlease enter a word: ";
cin>>word;
}
....
我一直在用其他编程语言工作,经常与NULL值进行比较,但在C++中似乎情况不同。错误提示是:
错误:'word == 0' 中没有适配的 'operator=='。
我在想,我只是在将一个值与NULL进行比较,但我真的不知道为什么会出错。在C++中,将一个值与NULL进行比较是否与其他语言不同?请教一下,谢谢。
注:我了解Ruby比Java更多。
std::string
设置为 null(如果运行此操作,将抛出异常)。std::string word;
是一个空字符串。 - chrisNULL
。但不能将对象设置为NULL
。 - Mysticial