C-Language SSCANF usage parsing and regular expression support

Source: Internet
Author: User
Tags sprintf

The basic knowledge of recent learning algorithms and input and output, first of all I wrote a code reference and learned a lot of resources

The references are given later, and they are written in more detail, and the support of regular expressions is indeed a big highlight.

#include <iostream>#include<string>#include<cstdio>using namespacestd;//characters and other types of conversion function LearningintMain () {//Print to a stringcout <<"tips for printing to a string \ n"; Chars[ -]; sprintf (s),"%d",123);//Convert integer to charactercout << S <<Endl; sprintf (s),"%5d%5d",123,46578);//format control, left-justifiedcout << S <<Endl; sprintf (s),"%-5d%-5d",123,46578);//format control, right-alignedcout << S <<Endl; sprintf (s),"%8x",14567);//16 binary Printingcout << S <<Endl; cout<<"reads data from a string that matches the specified format \ n"; //convert strings to numbers    intN; Chars0[ -] ="0123456"; SSCANF (S0,"%d", &n);//leading 0 will be filteredcout << N <<Endl; SSCANF (S0,"%2d", &n);//Bitwise width, 01-->1cout << N <<Endl; Chars1[ $]; SSCANF ("123456","%s", S1); cout<< s1<<Endl; SSCANF ("123456ABCD","%[^b]", S1);//takes the specified charactercout << S1 <<Endl; SSCANF ("123abEFac","%[^a-z]", S1);//take to uppercase characterscout << S1 <<Endl; stringS3 =S1; cout<<S3; return 0;}

Resources:

Conversion of String, char *, char[] in C + +

Https://www.cnblogs.com/Pillar/p/4206452.html

Example of sscanf function usage

Http://www.cnblogs.com/zhuangwei/p/5296219.html

C-Language SSCANF usage parsing and regular expression support

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.