字符串的 Cout 给出了一个错误,并且很难获得一些见解帮助?
我找不到这段代码中的错误,有人可以洞察我吗?我运行了调试,但错误是无法理解的。
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
string name;
cout << "Input your name please?" << endl;
cin >> name;
if
{
(name == "Bart Simpson")
cout << "You have been very naughty" << endl;
}
return 0;
}
I cant find the error in this piece of code could anyone please insight me? I ran the debugging but the errors are un-understandable..
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
string name;
cout << "Input your name please?" << endl;
cin >> name;
if
{
(name == "Bart Simpson")
cout << "You have been very naughty" << endl;
}
return 0;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
问题:
#include
,这可能导致您的初始编译器错误。if
语句存在简单的语法错误。以下内容应按您的预期工作:(
您需要包含
std::string
和std::getline
的string
以及ostream
为std::endl
。)Problems:
#include
s, which probably caused your initial compiler errors.if
statement.The following should work as you expect:
(You need to include
string
forstd::string
andstd::getline
, andostream
forstd::endl
.)我认为括号放在错误的位置只是粘贴代码时的问题
name
永远不会等于"Bart Simpson"
,因为提取字符串
在遇到空格时会停止;所以它只会是“Bart”
。也许您想使用getline()
来代替?I assume the bracket in the wrong place is just a problem when pasting the code
name
will never equal"Bart Simpson"
, since extracting astring
stops when it encounters whitespace; so it would only be"Bart"
. Perhaps you want to usegetline()
instead?应该是
并且您需要包含
Should be
And you need to include
<string>