成都网站建设设计

将想法与焦点和您一起共享

c++中的换行符怎么用

这篇文章主要介绍了c++中的换行符怎么用的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇c++中的换行符怎么用文章都会有所收获,下面我们一起来看看吧。

创新互联服务项目包括黄平网站建设、黄平网站制作、黄平网页制作以及黄平网络营销策划等。多年来,我们专注于互联网行业,利用自身积累的技术优势、行业经验、深度合作伙伴关系等,向广大中小型企业、政府机构等提供互联网行业的解决方案,黄平网站推广取得了明显的社会效益与经济效益。目前,我们服务的客户以成都为中心已经辐射到黄平省份的部分城市,未来相信会继续扩大服务区域并继续获得客户的支持与信任!

c++换行符有哪些

\n 换行,光标移到下一行的开头;

endl,把缓冲槽的内容输出到控制台;

\r 回车,光标移到当前行的开头,不会换到下一行,如果接着输出的话,本行以前的内容会被逐一覆盖;

#include 
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"<

结果:

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
#include
  
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++中的换行符怎么用”这篇文章的内容就介绍到这里,感谢各位的阅读!相信大家对“c++中的换行符怎么用”知识都有一定的了解,大家如果还想学习更多知识,欢迎关注创新互联行业资讯频道。


本文名称:c++中的换行符怎么用
网站URL:http://chengdu.cdxwcx.cn/article/gjcjed.html