在本篇文章里小编给大家整理的是关于c++换行符知识点总结,需要的朋友们可以参考学习下。
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++换行符知识点总结的文章就介绍到这了,更多相关c++换行符有哪些内容请搜索得得之家以前的文章希望大家以后多多支持得得之家!
织梦狗教程
本文标题为:c++换行符知识点总结


基础教程推荐
猜你喜欢
- 实例详解C#实现http不同方法的请求 2022-12-26
- C#中 Json 序列化去掉null值的方法 2022-11-18
- C#获取指定目录下某种格式文件集并备份到指定文件夹 2023-05-30
- C#通过标签软件Bartender的ZPL命令打印条码 2023-05-16
- C#中的Linq to JSON操作详解 2023-06-08
- Unity 如何获取鼠标停留位置下的物体 2023-04-10
- Unity shader实现高斯模糊效果 2023-01-16
- C#调用摄像头实现拍照功能的示例代码 2023-03-09
- C# 解析XML和反序列化的示例 2023-04-14
- c# – USING块在网站与Windows窗体中的行为不同 2023-09-20