Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) StdVectorExample4

 

Cpp98Qt CreatorLubuntuWindows

 

std::vector example 4: remove an element with preserving the order is a std::vector example that demonstrates how to remove an element with preserving the order.

 

Technical facts

 

Operating system(s) or programming environment(s)

IDE(s):

Project type:

C++ standard:

Compiler(s):

Libraries used:

 

 

 

 

 

Qt project file: ./CppStdVectorExample4/CppStdVectorExample4.pro

 

TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt

QMAKE_CXXFLAGS += -std=c++11 -Wall -Wextra -Weffc++
unix {
  QMAKE_CXXFLAGS += -Werror
}

SOURCES += main.cpp

 

 

 

 

 

./CppStdVectorExample4/main.cpp

 

#include <cassert>
#include <vector>

int main()
{
  std::vector<int> v { 1,4,9,16,25 };

  const std::size_t index = 2;
  assert(v[index] == 9 && "Erase the 9");
  v.erase( v.begin() + index);

  const std::vector<int> expected { 1,4,16,25 };
  assert(v == expected );
}

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict

This page has been created by the tool CodeToHtml