Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //none made by me
- #include <cstring>
- #include <iostream>
- #include <vector>
- #include <string>
- #include <sstream>
- #include <iterator>
- int main()
- {
- //1
- char input[100] = "A bird came down the walk";
- char *token = std::strtok(input, " ");
- while (token != NULL) {
- std::cout << token << '\n';
- token = std::strtok(NULL, " ");
- }
- //2
- std::string str = "This is a string";
- std::istringstream buf(str);
- std::istream_iterator<std::string> beg(buf), end;
- std::vector<std::string> tokens(beg, end); // done!
- for(auto& s: tokens)
- std::cout << '"' << s << '"' << '\n';
- //3
- std::string s = "scott>=tiger>=mushroom";
- std::string delimiter = ">=";
- size_t pos = 0;
- std::string ttoken;
- while ((pos = s.find(delimiter)) != std::string::npos) {
- ttoken = s.substr(0, pos);
- std::cout << ttoken << std::endl;
- s.erase(0, pos + delimiter.length());
- }
- std::cout << s << std::endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement