欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

c++換行符知識(shí)點(diǎn)總結(jié)

 更新時(shí)間:2020年03月03日 10:14:51   作者:angryTom  
在本篇文章里小編給大家整理的是關(guān)于c++換行符知識(shí)點(diǎn)總結(jié),需要的朋友們可以參考學(xué)習(xí)下。

c++換行符有哪些

\n 換行,光標(biāo)移到下一行的開頭;

endl,把緩沖槽的內(nèi)容輸出到控制臺(tái);

\r 回車,光標(biāo)移到當(dāng)前行的開頭,不會(huì)換到下一行,如果接著輸出的話,本行以前的內(nèi)容會(huì)被逐一覆蓋;

#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)容補(bǔ)充:

關(guān)于遇到的問題實(shí)例:

遇到\r獲取\n的時(shí)候,替換為\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;
}

到此這篇關(guān)于c++換行符知識(shí)點(diǎn)總結(jié)的文章就介紹到這了,更多相關(guān)c++換行符有哪些內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

您可能感興趣的文章:

相關(guān)文章

最新評(píng)論