C++:将多进制字符串数据转换为数值

#include 
#include 
#include 
using namespace std;
 
void strSplit(const string& str, const char split, vector& res)
{
    if(str == "")
    {
        return;
    }
 
    string&& strs = str + split;
    size_t pos = strs.find(split);
 
    while(pos != string::npos)
    {
        res.emplace_back(strs.substr(0, pos));
        strs = move(strs.substr(pos + 1, strs.size()));
        pos = strs.find(split);
    }
}
 
template
vector hexToData(string hexStr)
{
    vector ret;
    vector hexData;
    strSplit(hexStr, ' ', hexData);
    for(auto& v : hexData)
    {
        unsigned long tmp;
        if(v.starts_with("0x") || v.starts_with("0x"))
        {
            tmp = stoul(v, nullptr, 16);
        }
        else if(v.starts_with("0"))
        {
       

你可能感兴趣的:(C/C++,c++)