且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在C ++中将空格分隔的字符串拆分为多个字符串?

更新时间:2022-11-14 16:43:25

您正在问如何拆分字符串。 Boost有一个有用的实用程序boost :: split()

You are asking how to split a string. Boost has a helpful utility boost::split()

http://www.boost.org/doc/libs/1_48_0/doc/html/string_algo/usage.html#id3115768

这里有一个例子,将结果的单词放入一个向量:

Here's an example that puts the resulting words into a vector:

#include <boost/algorithm/string.hpp>
std::vector<std::string> strs;
boost::split(strs, "string to split", boost::is_any_of("\t "));