I am currently learning STL, and am on a topic of mapping, filtering etc. I recently learned lots of new stuff such as the new c++11 for loop(with auto) I (kinda) don't understand the way things work, but i wanted to use the "transform" function to fill up another vector(mapping topic). But after i build the program and run it, it gives me an error which goes as: "cannot seek value-initialized vector iterator"
I am not sure what that means or what error there is, could you guys help me understand the for loop concept and what im doing wrong here?
p.s the operator of the "transform" in the end was done with a lambda thingy(which i still have to learn and have no idea about) in the tutorial, i tried to make a function and guessed that it would work.
int mult(int a) {
return a * 10;
}
int main() {
vector<int> v{ 1,2,3,4,5 };
vector<int> v1;
for (auto& i : v) {
cout << i << endl;
}
if (v1.empty()) cout << "v1 is empty" << endl;
cout << "v1" << endl;
transform(v.begin(), v.end(), v1.begin(), mult);
for (auto &i : v1) {
cout << i << endl;
}
}
Aucun commentaire:
Enregistrer un commentaire