【问题标题】:split string in ',' C++ [duplicate]在','C ++中拆分字符串[重复]
【发布时间】:2017-10-13 09:15:22
【问题描述】:

我有一个这样的字符串:

17, the day is beautiful , day

。 我想在第一个','中拆分这个字符串。 例如,我想取 2 个字符串。一个代表17,两个代表美好的一天,一天

【问题讨论】:

  • std::getline 函数实际上可以使用任意字符作为“行结束符”,而不仅仅是换行符。它可以与std::istringstream一起用于这样的字符串“拆分”。
  • 既然您正在寻找第一个东西 string::find_first_of 是一个很好的匹配;)

标签: c++ string split


【解决方案1】:
#include <boost/algorithm/string.hpp>
std::vector<std::string> strs;
boost::split(strs, "17, 132, asdasd, 111", boost::is_any_of(","));

【讨论】:

  • 我有两个','但我只想先拆分。在您的示例中,我想在向量 17 和 132、asdasd、111 中取 2 个元素
猜你喜欢
  • 2021-04-01
  • 2010-09-21
  • 1970-01-01
  • 2023-03-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-09-18
  • 1970-01-01
相关资源
最近更新 更多