I have a vector with some values (3, 3, 6, 4, 9, 6, 1, 4, 6, 6, 7, 3), and I want to replace each 3 with a 54 or each 6 with a 1, for example and so on.
So I need to
The tool for the job is std::replace:
std::vector vec { 3, 3, 6, /* ... */ }; std::replace(vec.begin(), vec.end(), 3, 54); // replaces in-place
See it in action.