Advertisement
kutuzzzov

Урок 9-1 совершенствуем парсинг строки

Dec 28th, 2022
1,905
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include <string_view>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. vector<string_view> SplitIntoWordsView(string_view str) {
  7.     vector<string_view> result;
  8.     //int64_t pos = 0;
  9.     const int64_t pos_end = str.npos;
  10.     while (true) {
  11.         int64_t space = str.find(' ', 0);
  12.         result.push_back(space == pos_end ? str.substr(0) : str.substr(0, space - 0));
  13.         if (space == pos_end) {
  14.             break;
  15.         } else {
  16.             str.remove_prefix(space + 1);
  17.         }
  18.     }
  19.  
  20.     return result;
  21. }
  22.  
  23. int main() {
  24.   auto answer = SplitIntoWordsView("saga; sa;a aasdf se  ");
  25.   return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement