Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/153.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;boost::首先拆分_C++_Boost_Split - Fatal编程技术网

C++ C++;boost::首先拆分

C++ C++;boost::首先拆分,c++,boost,split,C++,Boost,Split,我有一个拆分字符串的函数: boost::split(r,lines[i], boost::is_any_of("=")); 上面的代码按每个“=”拆分字符串我想将此代码转换为只按一个“=”拆分。 例如: 拆分后: __ga 223478=90234=234 如何执行此操作?此操作不需要Boost。一种可能的解决方案是使用并创建两个字符串,并使用以下结果: #include <iostream> #include <string> int main() {

我有一个拆分字符串的函数:

boost::split(r,lines[i], boost::is_any_of("="));
上面的代码按每个“=”拆分字符串我想将此代码转换为只按一个“=”拆分。 例如:

拆分后:

__ga
223478=90234=234

如何执行此操作?

此操作不需要Boost。一种可能的解决方案是使用并创建两个字符串,并使用以下结果:

#include <iostream>
#include <string>

int main()
{
    std::string name_value = "__ga=223478=90234=234";
    std::string name;
    std::string value;

    const auto equals_idx = name_value.find_first_of('=');
    if (std::string::npos != equals_idx)
    {
        name = name_value.substr(0, equals_idx);
        value = name_value.substr(equals_idx + 1);
    }
    else
    {
        name = name_value;
    }

    std::cout << name << std::endl
              << value << std::endl;

    return 0;
}
#包括
#包括
int main()
{
std::string name_value=“\uuu ga=223478=90234=234”;
std::字符串名;
std::字符串值;
常量自动等于名称值。首先查找('=');
如果(std::string::npos!=equals_idx)
{
name=name\u value.substr(0,等于idx);
value=name\u value.substr(等于\u idx+1);
}
其他的
{
name=name\u值;
}
标准::cout
#include <iostream>
#include <string>

int main()
{
    std::string name_value = "__ga=223478=90234=234";
    std::string name;
    std::string value;

    const auto equals_idx = name_value.find_first_of('=');
    if (std::string::npos != equals_idx)
    {
        name = name_value.substr(0, equals_idx);
        value = name_value.substr(equals_idx + 1);
    }
    else
    {
        name = name_value;
    }

    std::cout << name << std::endl
              << value << std::endl;

    return 0;
}
__ga 223478=90234=234