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