Guest User

Untitled

a guest
Feb 20th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <iostream>
  3.  
  4. #include <boost/algorithm/string.hpp>
  5.  
  6. using namespace std;
  7. using namespace boost;
  8.  
  9. int main ()
  10. {
  11. printf("stroka = ");
  12. string s;
  13. getline(cin, s);
  14. vector<string> words;
  15. split(words, s, is_any_of(" "));
  16.  
  17. printf("%lu", words.size());
  18.  
  19. }
  20.  
  21. using namespace std;
  22. class Str_tokens {
  23. vector<string> v;
  24. public:
  25. Str_tokens(const string &s = "")
  26. {
  27. typedef std::istream_iterator<std::string> I;
  28.  
  29. std::istringstream is(s);
  30. std::copy( I(is), I(), std::back_inserter(v));
  31. }
  32. string& operator [](size_t n) {
  33. if (n < v.size())
  34. return v[n];
  35. return v.back();
  36. }
  37. size_t size() const { return v.size(); }
  38. };
  39.  
  40. int main()
  41. {
  42. Str_tokens v("using namespace std;");
  43. vector<string> words;
  44. for (int i = 0; i < v.size(); ++i)
  45. words.emplace_back(v[i]);
  46. // дальше можно одинаково использовать и words и обьект v
  47.  
  48. return 0;
  49. }
Add Comment
Please, Sign In to add comment