我是个新手,在看书呢,第一章就与到问题了.
书上源程序是:
#include <iostream>
int main ()
{
int x = 5;
int y = 7;
std::cout << endl;
std::cout << x + y << "" << x * y ;
std::cout << end;
return 0;
}
可是编译执行的时候不成功,下面的提示是什么意思?如何解决?
1>------ 已启动生成: 项目: hello, 配置: Debug Win32 ------
1>正在编译...
1>hello.cpp
1>c:\users\明阳\documents\visual studio 2008\projects\hello\hello\hello.cpp(6) : error C2065: “endl”: 未声明的标识符
1>c:\users\明阳\documents\visual studio 2008\projects\hello\hello\hello.cpp(8) : error C2065: “end”: 未声明的标识符
1>生成日志保存在“file://c:\Users\明阳\Documents\Visual Studio 2008\Projects\hello\hello\Debug\BuildLog.htm”
1>hello - 2 个错误,0 个警告
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========
关于C++ end问题
答案:5 悬赏:80
解决时间 2021-02-26 18:53
- 提问者网友:低唤何为爱
- 2021-02-26 12:55
最佳答案
- 二级知识专家网友:废途浑身病态
- 2021-02-26 13:26
endl和end在这里都是无法识别的,所以提示“未声明的标识符 ”。
你应该写成:
std::cout << std::endl;
std::cout << x + y << "" << x * y ;
std::cout << std::endl;
给你解释一下
std是命名空间,::(两个冒号)是域操作符,cout, cin和endl都是命名空间std里定义的,所以使用时必须加上std::
你应该写成:
std::cout << std::endl;
std::cout << x + y << "" << x * y ;
std::cout << std::endl;
给你解释一下
std是命名空间,::(两个冒号)是域操作符,cout, cin和endl都是命名空间std里定义的,所以使用时必须加上std::
全部回答
- 1楼网友:兮沫♡晨曦
- 2021-02-26 17:02
是endl不是end
#include <iostream>
int main ()
{
int x = 5;
int y = 7;
std::cout << endl;
std::cout << x + y << "" << x * y ;
std::cout << endl;
return 0;
}
- 2楼网友:寂寞的炫耀
- 2021-02-26 16:38
std::cout << end;
应该是std::cout << endl;
<iostream>
改为<iostream.h>
- 3楼网友:没感情的陌生人
- 2021-02-26 15:34
#include int main () { int x = 5; int y = 7; std::cout << std::endl; std::cout << x + y << "" << x * y ; std::cout << std::endl; return 0; }
- 4楼网友:厭世為王
- 2021-02-26 13:56
需要加上名字空间:std::cout<<std::endl;
或者你在include语句后加一句:using namespace std;
然后就可以这样用:cout<<endl;
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯