c++换行符知识点总结
作者:angryTom 时间:2022-10-05 13:53:01
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;
}
来源:https://www.php.cn/csharp-article-434353.html
标签:c++,换行符
0
投稿
猜你喜欢
Android中判断网络连接是否可用及监控网络状态
2022-09-07 05:24:25
Spring Boot如何通过自定义注解实现日志打印详解
2022-07-04 14:10:18
通过WIFI(不用数据线)连接Android手机调试
2023-01-05 18:20:45
Java中的Kotlin 内部类原理
2021-10-26 23:02:13
Java servlet、filter、listener、interceptor之间的区别和联系
2023-11-02 15:32:17
Android实现动态高斯模糊效果
2021-07-02 16:56:09
C#中使用资源的方法分析
2022-01-16 16:27:02
Java读取properties配置文件的8种方式汇总
2022-05-03 17:11:34
Java冒泡排序及优化介绍
2023-11-11 13:05:51
jdbc和mybatis的流式查询使用方法
2023-08-24 15:39:25
Java字节与字符流永久存储json数据
2022-12-27 21:10:13
Android Shader应用开发之霓虹闪烁文字效果
2022-09-11 16:43:20
使用sharding-jdbc实现水平分库+水平分表的示例代码
2023-11-05 03:21:50
SpringBoot3.0自定stater模块的操作流程(chatGPT提供的49种场景)
2023-06-15 05:21:46
listView的item中有checkbox,导致setOnItemClick失效的原因及解决办法
2022-09-04 10:57:12
分享C#操作内存读写方法的主要实现代码
2022-10-08 08:08:44
Android实现的简单蓝牙程序示例
2021-06-27 01:23:44
spring定时任务执行两次及tomcat部署缓慢问题的解决方法
2022-12-27 09:53:25
C#读写xml文件方法总结(超详细!)
2023-11-23 13:16:40
Android RippleDrawable 水波纹/涟漪效果的实现
2022-05-24 23:12:37