小編給大家分享一下c++中換行符知識點有哪些,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
創(chuàng)新互聯(lián)建站主要從事網(wǎng)站設計制作、做網(wǎng)站、網(wǎng)頁設計、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務。立足成都服務景洪,十余年網(wǎng)站建設經(jīng)驗,價格優(yōu)惠、服務專業(yè),歡迎來電咨詢建站服務:18980820575
c++換行符有哪些
\n 換行,光標移到下一行的開頭;
endl,把緩沖槽的內容輸出到控制臺;
\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; cout<<"這是換"<<endl<<"行符"; return 0; }
結果:
this is the first line this is the third linee this is the fifth line First Second Second23 這是換 行符 Presss any key to continue
內容補充:
關于遇到的問題實例:
遇到\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++中換行符知識點有哪些”這篇文章的所有內容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內容對大家有所幫助,如果還想學習更多知識,歡迎關注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
當前名稱:c++中換行符知識點有哪些
分享鏈接:http://aaarwkj.com/article48/gpieep.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供面包屑導航、企業(yè)網(wǎng)站制作、網(wǎng)站策劃、云服務器、外貿建站、網(wǎng)站設計
聲明:本網(wǎng)站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)