#include #include using namespace std; string str = "a bc def"; string new_str = ""; int length = str.length(); int get_spaces_num(string str, int index) { int spaces_num = 0; while (str[index++] == ' ') spaces_num++; return spaces_num; } int main() { for (int i = 0; i < length; i++) { if (str[i] == ' ') i += get_spaces_num(str, i) - 1; new_str += str[i]; } cout << new_str << endl; return 0; }