c++換行符知識點總結(jié)
更新時間:2020年03月03日 10:14:51 作者:angryTom
在本篇文章里小編給大家整理的是關于c++換行符知識點總結(jié),需要的朋友們可以參考學習下。
c++換行符有哪些
\n 換行,光標移到下一行的開頭;
endl,把緩沖槽的內(nèi)容輸出到控制臺;
\r 回車,光標移到當前行的開頭,不會換到下一行,如果接著輸出的話,本行以前的內(nèi)容會被逐一覆蓋;
#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; cout<<"這是換"<<endl<<"行符"; return 0; }
結(jié)果:
this is the first line this is the third linee this is the fifth line First Second Second23 這是換 行符 Presss any key to continue
內(nèi)容補充:
關于遇到的問題實例:
遇到\r獲取\n的時候,替換為\0.
#include<string.h> #include<stdio.h> int main(int argc, char *argv[]) { char str[128]; while (fgets(str, 127, stdin)) { char *tmp = NULL; //去掉換行符 if (tmp = strstr(str, "\n")) *tmp = '\0'; //去掉回車符 if (tmp = strstr(str, "\r")) *tmp = '\0'; printf("---%s---\n", str); } return 0; }
到此這篇關于c++換行符知識點總結(jié)的文章就介紹到這了,更多相關c++換行符有哪些內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
您可能感興趣的文章:
相關文章
c# 自定義值類型一定不要忘了重寫Equals,否則性能和空間雙雙堪憂
這篇文章主要介紹了c# 自定義值類型一定不要忘了重寫Equals,幫助大家提高c# 程序的性能,感興趣的朋友可以了解下2020-08-08Unity存儲游戲數(shù)據(jù)的多種方法小結(jié)
這篇文章主要介紹了Unity存儲游戲數(shù)據(jù)的幾種方法,在游戲開發(fā)中,存儲游戲數(shù)據(jù)是非常重要的,因為游戲數(shù)據(jù)決定了游戲的各個方面,例如游戲的進度、玩家的成就、游戲的設置,需要的朋友可以參考下2023-02-02