1. 程式人生 > >C++中的回車(\n)和換行(\r)

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;  

}