静态变量的应用 strtok的实现

#include<iostream>
#include<cstdio>
#include<string>
#include<cmath>
#include<fstream>

#pragma warning(disable : 4996)

using namespace std;

int main() {
    char str[] = "this , is -- a sample ! string, ok;";
    //下面药性str中逐个抽取出被“,-!”这几个字符分割的字符串
    char *p = strtok(str, "  , . -!");
    while (p!=NULL)    
        //只要P != NULL,就说明找到了一个子串
    {
        cout << p << endl;
        p = strtok(NULL, ",.-!");
        //后续调用,第一个参数必须是null
    }


    return 0;
}

 

posted @   江南王小帅  阅读(18)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
点击右上角即可分享
微信分享提示