C++的一个简单问题

来源:百度知道 编辑:UC知道 时间:2024/06/17 11:28:02
#include <iostream>
using namespace std;
int main()
{
cout << "*****" << endl << "****"<< endl << "***" << endl << "**\n"<< "*\n";

return 0;
}
不能执行,而
#include <iostream>
using namespace std;
int main()
{
cout << "*****" << endl;
cout << "****\n";
cout << "***" << endl;
cout << "**\n";
cout << "*\n";

return 0;
}
却可以执行?

可以执行的,不知是否楼主RP问题,我原封不动复制代码,运行正常 ,楼上两个可以无视,没有语法错误,也不是需要cout问题,g++编译器,无错误无警告,编译正常,运行正常

因为你上面的那个有endl,endl的意思就相当于/n,就是换行的意思。
所以上面的endl后面的东西必须有cout重新输出!

语法错误了嘛

cout << "*****" << endl << "****"<< endl << "***" << endl << "**\n"<< "*\n";

这里面的endl,被当做变量了

可以这样写cout << "*****\n" <<"****\n"<< "***\n" << "**\n"<< "*\n";
endl后面一定要有“;”,不然程序不会把它当关键字的

第一个程序g++编译通过 运行正常

楼主是不是用了什么奇怪的编译器?