Syntax

C++ Sort a Container Syntax

In C++, sort a container: sorts elements in place — std::sort(v.begin(), v.end());

Quick Answer

Syntax
std::sort(v.begin(), v.end());
C++Syntax

Sort a Container

Code example
std::sort(v.begin(), v.end());

Sorts elements in place.

Learn More

How to sort a container in C++

  1. Open your C++ file or editor.
  2. Copy the example, then replace its sample names and values for your code.

C++ Sort a Container Syntax

Use std::sort(v.begin(), v.end());.

Related Syntax References

Frequently asked questions

What is the C++ syntax for sort a container?

Use this pattern: std::sort(v.begin(), v.end());

Can I copy this C++ code example?

Yes. Use Copy code and adapt the example to your program.

Is this C++ syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify