【发布时间】:2015-05-29 22:27:25
【问题描述】:
我还是编码新手,正在尝试找出简单的对话,编译时出现以下错误:
错误:无法从 'std:: 转换 'str.std::basic_string<_chart _traits _alloc>::operator=, std::allocator >(((const char*)"good"))' basic_string' 到 'bool' if (str = "good") {
和
错误:无法从 'std:: 转换 'str.std::basic_string<_chart _traits _alloc>::operator=, std::allocator >(((const char*)"bad"))' basic_string' 到 'bool' 否则 if (str = "bad") {
我从以下代码中得到这些错误。请记住,我对此还是很陌生:
// random practice on conversation
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string str;
string bad;
cout << "How has your day been? \n";
cin >> str;
if (str = "good") {
cout << "Thats good to hear!\n";
}
else if (str = "bad") {
cout << "That's too bad, what happened? \n";
cin >> bad;
cout << "I'm sorry to hear that...\n";
}
else {
cout << "I'm sorry, I couldn't understand you...\n";
}
}
【问题讨论】:
-
c++ 中的平等使用
==,而不是=。 -
然后解决了,这让我感觉更初学者,谢谢你的帮助。我不能也可以相信这是唯一的问题......哦,还有很多东西要学
-
你的编译器真的没有给你warning about = vs. ==吗?
-
我发布的是我得到的唯一两个错误,我使用的是编译器 DEV-C++ 5.10
标签: c++ string if-statement