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

‘\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;  

}  

猜你喜欢

转载自blog.csdn.net/juddi/article/details/83177084