endl是一个函数,而不是关键字。
#include
int main()
{
std::cout<
return 0;
}
要了解endl的图片,您首先需要了解“函数指针”主题。
看这段代码(用C语言写)
#include
int add(int, int);
int main()
{
int (*p)(int, int); /*p is a pointer variable which can store the address
of a function whose return type is int and which can take 2 int.*/
int x;
p=add; //Here add is a function without parenthesis.
x=p(90, 10); /*if G is a variable and Address of G is assigned to p then
*p=10 means 10 is assigned to that which p points to, means G=10
similarly x=p(90, 10); this instruction simply says that p points to add
function then arguments of p becomes arguments of add i.e add(90, 10)
then add function is called and sum is computed.*/
printf("Sum is %d", x);
return 0;
}
int add(int p, int q)
{
int r;
r=p+q;
return r;
}
编译此代码,然后查看输出。
返回主题...
#include
//using namespace std;
int main()
{
std::cout<
return 0;
}
iostream文件包含在此程序中,因为iostream文件中存在cout对象的原型,而std是命名空间。 之所以使用它,是因为命名空间std中存在cout和endl的定义(库文件)。或者,您也可以在顶部使用“使用命名空间std”,因此不必在每个cout或endl之前都写“ std :: coutn << .....”。
当您在不带括号的情况下编写endl时,可以将函数endl的地址提供给cout,然后调用endl函数并更改行。这背后的原因是
namespace endl
{
printf("\n");
}
结论:在C ++之后,C代码正在运行。