Is there a way to implement analog of Python's 'separator'.join() in C++?

后端 未结 6 617
傲寒
傲寒 2021-02-07 03:44

All I\'ve found is boost::algorithm::string::join. However, it seems like overkill to use Boost only for join. So maybe there are some time-tested recipes?

<
6条回答
  •  既然无缘
    2021-02-07 04:33

    If you use Qt in your project you can directly use the join function of QString (QString Reference) and it works as expected from python. Some examples:

    QStringList strList;
    qDebug() << strList.join(" and ");
    

    Result: ""

    strList << "id = 1";
    qDebug() << strList.join(" and ");
    

    Result: "id = 1"

    strList << "name = me";
    qDebug() << strList.join(" and ");
    

    Result: "id = 1 and name = me"

提交回复
热议问题