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

180it 2020-02-06 PM 1784℃ 0条

'\n' 换行,光标移到下一行的开头;
'\r' 回车,光标移到当前行的开头,不会换到下一行,如果接着输出的话,本行以前的内容会被逐一覆盖;

#include <iostream>
using namespace std;    
int main()  
{  
    cout << "this is the first line\n";  
    cout << "this is the second line\r";  
    cout << "this is the third line\n";  
    cout << "this is the fouth line\r";  
    cout << "this is the fifth line\n"; 
    cout<<"First"<<"\n"<<"Second"<<endl; 
    cout<<"First123"<<"\r"<<"Second"<<endl;  
    return 0;  
} 

 
————————————————

原文链接:https://blog.csdn.net/juddi/article/details/83177084

支付宝打赏支付宝打赏 微信打赏微信打赏

如果文章或资源对您有帮助,欢迎打赏作者。一路走来,感谢有您!

标签: none

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