yuelien 2015-12-09 14:19 采纳率: 50%
浏览 1888
已采纳

C++可以用指针数组从字符串中提取子字符串么?

C++可以用指针数组从字符串中提取子字符串么?
如果可以请给一个示范QAQ

  • 写回答

3条回答 默认 最新

  • ysuwood 2015-12-09 14:27
    关注

    http://www.cnblogs.com/xiangzi888/archive/2012/04/16/2451947.html

    /* strtok example */
    #include <stdio.h>
    #include <string.h>
    
    int main (void)
    {
        char str[] = "- This, a sample string.";
        char *pch;
        printf("Splitting string \"%s\" into tokens:\n", str);
        pch = strtok(str," ,.-");
        while (pch != NULL)
        {
            printf("%s\n", pch);
            pch = strtok(NULL, " ,.-");
        }
        printf("at the end: %s", str);
        return 0;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?