sscanf() 函数 最近几次才接触到!
这里记录一下:
sscanf: Read formatted data from string 从字符串中读取与指定格式相同的数据
case:
#include
#include //该函数存在于此头文件中
#include
using namespace std;
int main()
{
char str[]="hello, bill 156";
int num;
char s1[20],s2[20];
sscanf(str,"%s %s %d",s1,s2,&num);//str 是待查找字符串 s1,s2,num是存储截取的特定格式的数据
cout<"<"<
sscanf(str,"%s %d ....",s,&num.....)
参数说明:str是待读取的字符串 后面的依次是 格式设置 读取特定格式数据的接收
sscanf(str+5,"%d%n",&num,&i)
这个格式的应用是:如果str的第5个字符是数字的话 后面还有连续i个数字字符的话 可以将这些连续的数字字符截取 并存在num中
#include
#include
#include
using namespace std;
int main()
{
int i;
char str[]="hell123658obill156";
int num;
sscanf(str+5,"%d%n",&num,&i);
cout<