I'm new to C++. I'm trying to solve a problem which goes something like this:
Q: create varies string vectors, and using iterator to change those strings to uppercase.
Below is the code I came up with. However, the IDE always output error. Because I'm new to C++, I don't have enough knowledge to fix the problem.
#include <iostream>
#include <string>
#include <vector>
#include <iterator>
using namespace std;
void checkAndPrint(vector<string> &vec) {
cout << "content: [";
for (auto it = vec.begin(); it != vec.end(); ++it) {
for (char c : it) {
c = toupper(c);
cout << c;
}
}
cout << "]\n" << endl;
}
int main() {
vector<string> s1;
vector<string> s2(10);
vector<string> s3(10, "hello");
vector<string> s4{10, "world"};
vector<string> s5{"good", "morning"};
vector<string> s6{10, "10"};
checkAndPrint(s1);
checkAndPrint(s2);
checkAndPrint(s3);
checkAndPrint(s4);
checkAndPrint(s5);
checkAndPrint(s6);
}
Error:
error: invalid range expression of type 'std::__1::__wrap_iter<std::__1::basic_string<char> *>'; did you mean to dereference it with '*'?
for (char c : it) {
^
*