Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <iostream>
- #include <boost/algorithm/string.hpp>
- using namespace std;
- using namespace boost;
- int main ()
- {
- printf("stroka = ");
- string s;
- getline(cin, s);
- vector<string> words;
- split(words, s, is_any_of(" "));
- printf("%lu", words.size());
- }
- using namespace std;
- class Str_tokens {
- vector<string> v;
- public:
- Str_tokens(const string &s = "")
- {
- typedef std::istream_iterator<std::string> I;
- std::istringstream is(s);
- std::copy( I(is), I(), std::back_inserter(v));
- }
- string& operator [](size_t n) {
- if (n < v.size())
- return v[n];
- return v.back();
- }
- size_t size() const { return v.size(); }
- };
- int main()
- {
- Str_tokens v("using namespace std;");
- vector<string> words;
- for (int i = 0; i < v.size(); ++i)
- words.emplace_back(v[i]);
- // дальше можно одинаково использовать и words и обьект v
- return 0;
- }
Add Comment
Please, Sign In to add comment