yuelien
2015-12-09 14:19
采纳率: 50%
浏览 1.8k

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;
    }
    
    打赏 评论
  • DeathWish_pan 2015-12-10 04:21

    /* strtok example */
    #include
    #include

    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;
    }

    打赏 评论
  • John_ToString 2015-12-11 02:52
    打赏 评论

相关推荐 更多相似问题