How to replace specific values in a vector in C++?
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 go through the vector first, get the [i] value, search and replace each 3 with a 54, but still keep relevant positions.std::set is vector::swap a good way? I am not even sure how to begin this :( I can't use push_back as that would not keep the correct order of values as that is important. Please keep it simple; I am just a beginner :) The tool for the job is std::replace : std::vector<int> vec { 3, 3, 6, /* ... */ }; std::replace