c++ deleting spaces
Welcome dear fellow members. I am struggling with some sphere online judge tasks and I would be very grateful if somebody could help me understand how the word splitting code works and how to implement some functionalities such as saving each character to separate cell in a table. The code: // C++ program to print words in a sentence #include <bits/stdc++.h> using namespace std; void removeDupWord(string str) { string word = ""; for (auto x : str) { if (x == ' ') { cout << word << endl; word = ""; } else { word = word + x; } } cout << word << endl; } // Driver function int main() { string str = "1 23 4 5"; removeDupWord(str); return 0; } This program works fine and shows the numbers in new lines. But is it possible to cout each cell of the string "word" ? for example cout << word[i] << endl; ? And why the first for loop uses "auto: x" ? Thank You in advance