C语言sscanf用法解析与正则表达式支持
最近学习算法和输入输出用到的基本知识,首先是我自己写的一份代码参考和学习了很多资源
后面会给出参考资料,他们写得更加详细,正则表达式的支持确实是一大亮点所在
#include<iostream>
#include<string>
#include<cstdio>
using namespace std; //字符与其他类型转换函数学习 int main()
{
//打印到字符串中
cout << "打印到字符串中的技巧\n";
char s[];
sprintf(s, "%d", );//整数转为字符
cout << s << endl;
sprintf(s, "%5d %5d", ,);//格式控制,左对齐
cout << s << endl;
sprintf(s, "%-5d %-5d", , );//格式控制,右对齐
cout << s << endl;
sprintf(s, "%8x", );//16进制打印
cout << s << endl;
cout << "从字符串中读取与指定格式相符的数据\n";
//字符串转换为数字
int N;
char s0[] = "";
sscanf(s0, "%d", &N);//前导0会被过滤
cout << N << endl;
sscanf(s0, "%2d", &N);//按位取宽,01-->1
cout << N << endl;
char s1[];
sscanf("", "%s", s1);
cout << s1<< endl;
sscanf("123456abcd", "%[^b]", s1);//取到指定字符为止
cout << s1 << endl;
sscanf("123abEFac", "%[^A-Z]", s1);//取到大写字符为止
cout << s1 << endl;
string s3 = s1;
cout << s3;
return ;
}
参考资料:
C++中string、char *、char[]的转换
https://www.cnblogs.com/Pillar/p/4206452.html
sscanf函数用法举例
http://www.cnblogs.com/zhuangwei/p/5296219.html
C语言sscanf用法解析与正则表达式支持的更多相关文章
- C语言 sscanf用法详解
/* sscanf用法详解 */ #include <stdio.h> /* sscanf头文件 */ #include <stdlib.h> #include <str ...
- C语言setjmp用法解析
https://www.cnblogs.com/hbiner/p/3261437.html
- extern "c"用法解析
转自: extern "c"用法解析 - 简书 引言 C++保留了一部分过程式语言的特点,因而它可以定义不属于任何类的全局变量和函数.但是,C++毕竟是一种面向对象的程序设计语言, ...
- extern "C" 用法解析
extern "c"用法解析 作者 作者Jason Ding ,链接http://www.jianshu.com/p/5d2eeeb93590 引言 C++保留了一部分过程式语言的 ...
- C/C++之extern "C"的用法解析
extern "C"的用法解析 http://blog.sina.com.cn/u/494a1ebc010004g5 C++中extern “C”含义深层探索 1.引言 C++语言 ...
- ZT extern "C"的用法解析
extern "C"的用法解析 1.引言 C++语言的创建初衷是“a better C”,但是这并不意味着C++中类似C语言的全局变量和函数所采用的编译和连接方式与C语言完全相同. ...
- 标准SQL语言的用法
原文链接:http://www.ifyao.com/2015/05/18/%E6%A0%87%E5%87%86%E7%9A%84sql%E8%AF%AD%E8%A8%80%E4%BD%BF%E7%94 ...
- sql中的group by 和 having 用法解析
转载博客:http://www.cnblogs.com/wang-123/archive/2012/01/05/2312676.html --sql中的group by 用法解析:-- Group B ...
- sql中group by 和having 用法解析
--sql中的group by 用法解析:-- Group By语句从英文的字面意义上理解就是“根据(by)一定的规则进行分组(Group)”.--它的作用是通过一定的规则将一个数据集划分成若干个小的 ...
随机推荐
- iOS UI-AlertView(警示框)和ActionSheet(选择框、操作表单)
#import "ViewController.h" @interface ViewController ()<UIAlertViewDelegate,UIActionShe ...
- git忽略操作
在使用git的过程中,我们会有一些文件是不需要版本管理的,这时候就需要忽略这些文件 这里暂时只讲我用到的办法 全局忽略 在任意位置建立 .gitignore 文件,在其中写入你要忽略文件的规则(写法自 ...
- 15 int *ptr= (int *)(&a+1)跨了整个数组长度
分析以下程序,输出结果 2,5 #include<stdio.h> int main() { ]={,,,,}; ); printf(),*(ptr-)); ; } 分析: a 代表的是i ...
- [工作]双核系统struts-config.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts-config PUBLIC & ...
- Syntax error on token(s), misplaced construct(s)
Syntax error on token(s), misplaced construct(s)
- L1-008 求整数段和
给定两个整数A和B,输出从A到B的所有整数以及这些数的和. 输入格式: 输入在一行中给出2个整数A和B,其中−,其间以空格分隔. 输出格式: 首先顺序输出从A到B的所有整数,每5个数字占一行,每个数字 ...
- Translate Exercises(3) 科技英语翻译
[1] CMOS logic is a newer technology, based on the use of complementary MOS transistorsto perform lo ...
- tomcat部署和启动2
catalina run 启动服务器后,按下CTRL+C,停止服务器,选择"y",退回到正常命令行. catalina stop
- xmodmap: unable to open display '' Error: Couldn't connect to XServer passing null display
/********************************************************************************* * xmodmap: unable ...
- QT 5.4.1 for Android Windows环境搭建
QT 5.4.1 for Android Windows环境搭建 2015-5-13 目录 一.参考文章: 二.准备软件: 三.安装准备好的软件: 四.配置Qt 5.4.1 for Android 五 ...