0
点赞
收藏
分享

微信扫一扫

C++ string split 字符串

毅会 2022-02-13 阅读 92
#include <vector>
#include <string>
#include <algorithm>
#include <iostream>
#include <cstdint>
#include <string.h>

void str_split(char* src,const char* split,std::vector<std::string> &res){
     char* ptr = nullptr;
     
     while((ptr = strsep(&src,split)) != nullptr){
         res.push_back(std::string(ptr));
     }
}

int main(void){
    std::string debug = "hello world test";
    std::vector<std::string> res;

    str_split(const_cast<char*>(debug.c_str()),std::string(" ").c_str(),res);

    for(int i = 0 ; i < res.size() ; i++){
        std::cout << res[i] << std::endl;
    }

    return 0;
}
举报

相关推荐

0 条评论