- to use std::sort() on c-style arrays use std::begin(), std::end() instead of using the array size as a proxy for a 1 past the end iterator (see link in program)
- line 17: use the sizeof operator to right-size the vector, else as you can see you're missing the last element
- line 18: v1.begin() + 3 encapsulates all the elements of the vector, perhaps you want to split it a bit earlier for something non-trivial?
Thank's gunnerfunner for spending your time.
These codes are from C++ Institute tests and I don't understand which is, for them, the correct answer. You made a very good and interesting comment, but I stiil not understand which is the correct answer for c++ Institute
If the question is whether or not your program is well-formed, then the answer is yes, and the output is 0, 2, 3,.
The sort call on line 16 sorts all the numbers in the array.
The vector constructed on line 17 takes the first three numbers from that (now sorted) array
The invocation of std::inplace_merge() on line 18 does nothing interesting.
Finally the three elements of the vector are printed.
In the future you can check this by compiling your program.
Yes, it looks like they want you to read the code and determine if the output is the expected (0,2,3) or if there is something that will mess up the code.
Interesting that they ask if there is a runtime error rather than just compilation error, which means you don't just need to be aware of syntax but also buffer overflow and other errors that the compiler might not catch.
I notice you are posting several of these, since they are all along the same topic please consider putting them all in a single posting-thread.