c++ primer 第一章 c++ 程序格式

c++ primer 第一章 c++ 程序格式

参考书:

c++ primer (5th)

C++ programs are largely free-format, meaning that where we put curly braces, indentation, comments, and newlines usually has no effect on what our programs mean.

While you’re still in the mood for cout advice, you can also rewrite the concatenated version this way, spreading the single statement over four lines:

#include<iostream>
int main(void)
{
	std::cout << "Hello" << " " <<
				 "world"
		 << "!"
		 << std::endl;
	return 0;
}
Hello world!

That’s because C++’s free format rules treat newlines and spaces between tokens interchangeably.

C 语言不能这么写:

#include<stdio.h>
int main(void)
{
	printf("Hello
	 world
	 !
	 \n");
	return 0;
}

上面代码编译出错,但可以:

#include<stdio.h>
int main(void)
{
	printf("Hello\n"
	);
	return 0;
}

因此,c 语言如要输出长句,只能用三种方法:
printf() 输出长字符串

发布了120 篇原创文章 · 获赞 2 · 访问量 5783

猜你喜欢

转载自blog.csdn.net/Lee567/article/details/104080694