以下控制字符的含义:

回车 换行 换页


当前回答

“\n”是换行字符。这意味着结束当前行,并为正在阅读它的任何人转到新的行。

其他回答

Consider an IBM 1403 impact printer. CR moved the print head to the start of the line, but did NOT advance the paper. This allowed for "overprinting", placing multiple lines of output on one line. Things like underlining were achieved this way, as was BOLD print. LF advanced the paper one line. If there was no CR, the next line would print as a staggered-step because LF didn't move the print head. FF advanced the paper to the next page. It typically also moved the print head to the start of the first line on the new page, but you might need CR for that. To be sure, most programmers coded CRFF instead of CRLF at the end of the last line on a page because an extra CR created by FF wouldn't matter.

“\n”是换行字符。这意味着结束当前行,并为正在阅读它的任何人转到新的行。

这些是非印刷字符,与“新行”的概念有关。\n是换行。\r是回车。在不同的平台上,相对于有效的新行,它们有不同的含义。在windows中,新行是\r\n。在linux中,\n。在mac中,\r。

实际上,将它们放在任何字符串中,都会对字符串的打印结果产生影响。

\f用于换页。 在控制台中看不到任何效果。但是当你在文件中使用这个字符常量时,你就能看到区别了。

另一个例子是,如果你可以将输出重定向到一个文件,那么你就不必写文件或使用文件处理。

为例:

用c++编写以下代码

void main()    
{
    clrscr();
    cout<<"helloooooo" ;

    cout<<"\f";
    cout<<"hiiiii" ;

}

当你编译它的时候,它会生成一个exe(for exe . abc.exe)

然后你可以使用这个重定向输出到一个文件:

ABC > xyz.doc

然后打开xyz.doc文件,您可以看到helloo和hiiii....之间的实际分页符

在老式的纸质打印机终端上,前进到下一行需要两个动作:将打印头移回水平扫描范围的起点(回车)和前进正在打印的纸卷(换行)。

由于我们不再使用纸质打印机终端,这些动作已经无关紧要了,但用来发出信号的字符以各种形式存在。