Advertisement
Kazimirko

Основы С++ / Тема 2 / Урок 6. Цикл for и выход из цикла / Задача 3

Feb 15th, 2021
1,932
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.42 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main() {    
  7.     string query;
  8.     string word;
  9.    
  10.     getline(cin, query);
  11.  
  12.     for (int i = 0; i < query.size(); ++i) {
  13.         if (query[i] == ' ') {
  14.             cout << '[' << word << ']' << endl;
  15.             word = ""s;
  16.         } else {
  17.             word = word + query[i];
  18.         }
  19.        
  20.     }
  21.     cout << '[' << word << ']' << endl;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement