【问题标题】:QStringList alternative in STL or BoostSTL 或 Boost 中的 QStringList 替代方案
【发布时间】:2012-10-16 11:13:58
【问题描述】:

在 Boost 或 STL 中是否有任何替代 QStringList 的方法。我想要实现的是拆分路径,例如。 dvb://1.2.3.4/launchpad/dyn/index.htm 来分隔字符串,因为它可以通过简单地在 QString 列表中完成:

QStringList path = objectPath.split(QChar('/'), QString::SkipEmptyParts);

谢谢。

【问题讨论】:

标签: c++ string boost stl


【解决方案1】:

boost::split 可以根据一个或多个分隔符将字符串拆分为std::vector<std::string>

#include <vector>
#include <string>
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/split.hpp>

std::vector<std::string> path_parts;
std::string s("some/file/path");
boost::split(path_parts, s, boost::is_any_of("/"));

【讨论】:

    猜你喜欢
    • 2010-09-10
    • 2023-03-21
    • 1970-01-01
    • 1970-01-01
    • 2010-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-10
    相关资源
    最近更新 更多