I am new to C ++ and try to learn the concept of a vector. I saw this code on the Internet. My question is, what is the purpose of the inner for loop inside the for loop (auto & str: vec)? Why did the author create a second link (& c) to the first link (& str)?
int main() {
vector<string> vec;
for (string word; cin >> word; vec.push_back(word)) {
}
for (auto &str : vec) {
for (auto &c : str) {
c = toupper(c);
}
}
for (int i = 0; i != vec.size(); ++i) {
if (i != 0 && i % 8 == 0) cout << endl;
cout << vec[i] << " ";
}
cout << endl;
return 0;
}
source
share