以下控制字符的含义:
回车 换行 换页
以下控制字符的含义:
回车 换行 换页
当前回答
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.
其他回答
在老式的纸质打印机终端上,前进到下一行需要两个动作:将打印头移回水平扫描范围的起点(回车)和前进正在打印的纸卷(换行)。
由于我们不再使用纸质打印机终端,这些动作已经无关紧要了,但用来发出信号的字符以各种形式存在。
when I was an apprentice in the Royal Signals many (50) years ago, teletypes and typewriters had "Carriage" with the printing head on them. When you pressed RETURN the Carriage would fly to the left. Hence Carriage Return (CR). You could just return the Carriage, but on mechanical typewriters, you'd use the Lever (much like a tremolo lever on an electric guitar) which would also do the Line Feed. Your next question is why would you not want the line feed? heh heh well in those days to delete characters we'd do a CR then use a Tip-ex-like paper in between the hammerheads and paper and type the same keys to over-write with white ink. Some fancy typewriters had a key you could press. So there you go.
“\n”是换行字符。这意味着结束当前行,并为正在阅读它的任何人转到新的行。
看看维基百科:
基于ASCII或兼容字符集的系统分别使用LF(换行,'\n', 0x0A,十进制10)或CR(回车,'\r', 0x0D,十进制13),或CR后跟LF (CR+LF, 0x0D 0x0A)。这些字符是基于打印机命令的:换行指示一行纸应该从打印机输出,回车指示打印机的回车应返回到当前行的开头。
\r是回车,光标向后移动,就像我要做-一样
printf("stackoverflow\rnine")
ninekoverflow
表示已将光标移到“stackoverflow”的开头,并覆盖开始的4个字符,因为“nine”有4个字符长。
\n是新行字符,它改变行并将光标移到新行开头,如-
printf("stackoverflow\nnine")
stackoverflow
nine
\f是进给,它的用途已经过时了,但它被用于缩进
printf("stackoverflow\fnine")
stackoverflow
nine
如果我这样写
printf("stackoverflow\fnine\fgreat")
stackoverflow
nine
great