
str -- 要被分解茄镇成一组颤正粗小字符串的字符串。
delim -- 包含分隔符的 C 字符串。
int sscanf(const char *str, const char *format, ...)
char *strstr(const char *haystack, const char *needle)
haystack -- 要被检索的 C 字符串。
needle -- 在 haystack 字符串清首内要搜索的小字符串。
#include <stdio.h>#include <string.h>
// 将str字符以spl分割,存于dst中,并返大没搏回子字符串数量
int split(char dst[][80], char* str, const char* spl)
{
int n = 0
char *result = NULL
result = strtok(str, spl)
while( result != NULL )
{
strcpy(dst[n++], result)
result = strtok(NULL, spl)
}
return n
}
int main()
{
char str[] = "what is you name?"
滚祥 char dst[10][80]
int cnt = split(dst, str, " ")
for (int i = 0 i < cnt i++)
察皮 puts(dst[i])
return 0
}
#include<iostream>
#include<vector>
#include<sstream>
usingnamespacestd
intmain()
{
strings
vector<int>v
cin>>s
//将读入的字符串转化成is流
istringstreamis(s)
intinter
charch
while(is>>inter)//只能读出is流中的一个整形读进inter
{
v.push_back(inter)
is>>ch//然后读一个字符型读进ch
}
for(inti=0i<v.size()i++)
cout<<v[i]<<""
cout<没闭缓<endl
return0
}
扩展资料
C语言的字符串按照指定字符串分割 *** 作
#include<stdio.h>
#pragmawarning(disable:4996)
#include<stdlib.h>
intmain()
{
charstr[]="我,是态稿,中国,程序员"
char*ptr
char*p
printf("开枯模始前:str=%s\n",str)
printf("开始分割:\n")
ptr=strtok(str,",")
while(ptr!=NULL){
printf("ptr=%s\n",ptr)
ptr=strtok(NULL,",")
}
getchar()
}
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)