【问题标题】:how to extract words from a string in C++ [duplicate]如何从C ++中的字符串中提取单词[重复]
【发布时间】:2011-04-21 17:19:45
【问题描述】:

可能重复:
How do I tokenize a string in C++?

我有一个字符串“这是一个字符串”,我想遍历这个字符串中的所有单词。 有没有一种方法可以让我轻松做到这一点而无需解析它。

谢谢

【问题讨论】:

标签: c++


【解决方案1】:
void do_something(const std::string& word);

std::for_each( std::istream_iterator<std::string>(is)
             , std::istream_iterator<std::string>()
             , do_something );

【讨论】:

  • @wilx:谢谢,已修复。
猜你喜欢
  • 2021-09-23
  • 1970-01-01
  • 1970-01-01
  • 2019-05-21
  • 2017-11-09
  • 2016-12-27
  • 2017-02-04
  • 2017-02-14
  • 2012-10-27
相关资源
最近更新 更多