C++中回车换行(\n\r)和换行(\r)的区别

本文介绍了C++中回车( )和换行( )的区别,以及它们在不同操作系统中的表现。在Windows中,回车换行是 ,而在Unix和Mac系统中分别使用 和 作为换行。通过示例代码展示了这些字符如何影响输出,并讨论了其历史来源和在编程中的应用。
摘要由CSDN通过智能技术生成

windows下的点一下回车,效果是:回车换行,就是\r\n

unix系统下的回车一下就是一个\n

给出如下代码:

[cpp]  view plain  copy
 print ?
  1. #include <iostream>  
  2. using namespace std;  
  3.   
  4. int main()  
  5. {  
  6.     cout << "this is the first line\n";  
  7.     cout << "this is the second line\r";  
  8.     cout << "this is the third line\n";  
  9.     cout << "this is the fouth line\r";  
  10.     cout << "this is the fifth line\n";  
  11.     cout << "end" ;  
  12.     return 0;  
  13. }  

运行结果如下:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值