0
A
回答
2
使用stringstreams(<sstream>
头)
std::string str ="abcde fghijk";
std::istringstream iss(str);
std::string first, second;
iss >> first >> second;
4
使用分裂...
#include <boost/algorithm/string.hpp>
std::vector<std::string> strs;
boost::split(strs, "string to split", boost::is_any_of("\t "));
2
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <iterator>
#include <vector>
std::vector<std::string> get_words(std::string sentence)
{
std::stringstream ss(sentence);
std::istream_iterator<std::string> begin(ss);
std::istream_iterator<std::string> end;
return std::vector<std::string>(begin, end);
}
int main() {
std::string s = "abcde fghijk";
std::vector<std::string> vstrings = get_words(s);
//the vector vstrings contains the words, now print them!
std::copy(vstrings.begin(), vstrings.end(),
std::ostream_iterator<std::string>(std::cout, "\n"));
return 0;
}
输出:
abcde
fghijk
相关问题
- 1. 只检索字符串的一部分
- 2. C字符串搜索获取字符串的一部分
- 3. 在C++中部分字符串搜索
- 4. 在PHP中搜索字符串或字符串的一部分
- 5. 搜索部分字符串
- 6. C:评估字符串的一部分
- 7. C++使用字符串的一部分
- 8. c#包含字符串的一部分
- 9. C++ Tokenize字符串的一部分
- 10. 如何检索java中的一部分字符串?
- 11. 从python dataframe列检索字符串的一部分
- 12. 检索Ruby中的最后一部分字符串?
- 13. C获取字符串中的字符串的一部分
- 14. 用于检索部分字符串字段的脚本字段
- 15. 检索python中只有一部分字符串
- 16. 字符串的某些部分后检索数字
- 17. 检索字符串使用Oracle SQL中的某些字符串 - 第2部分
- 18. 将字符串的一部分移动到字符串的另一部分
- 19. 将字符串的一部分复制到另一个C#中的字符串
- 20. C#选择字符串的一部分时,有一个匹配结果字符串的一部分
- 21. 如何搜索字符串的一部分,不是全部
- 22. 检查字符串1的任何部分字符串2
- 23. 如何在java中检索字符串的特定部分
- 24. 如何检索字符串的某个部分
- 25. 检索所有出现的部分字符串
- 26. 斯威夫特3 - 检索字符串的特定部分
- 27. 从PHP中的字符串检索部分内容
- 28. 检查一个数组中的字符串的一部分
- 29. 仅检索字段的一部分
- 30. TSql字符串搜索模仿部分字符串确切和部分不
查看http://stackoverflow.com/questions/236129/how-to-split-a-string-in-c – 2011-06-12 00:43:41