This blog article shows you one of the ways to install C++ into Ubuntu 20.04. Although a lot of article out there showing it possible to use the command gcc to compile C++ instead of just C but I could not. I use g++ command to compile C++ program in Ubuntu. I perform the following to get g++. I got it in the build-essential bundle instead than looking for only g++ to install. In most of the web site they will show you the following 3 steps to install. Somehow, if you are as unluckily as I do then you will hit error during the second command.
$ sudo apt update
$ sudo apt install build-essential
Error —————————————————————————————————-
chanmm@chanmm-Virtual-Machine:~$ sudo apt install build-essential
Reading package lists… Done
Building dependency tree
Reading state information… Done
You might want to run ‘apt –fix-broken install’ to correct these.
The following packages have unmet dependencies:
build-essential : Depends: g++ (>= 4:9.2) but it is not going to be installed
Depends: make
Depends: dpkg-dev (>= 1.17.11) but it is not going to be installed
codelite : Depends: libncurses5 but it is not going to be installed
Recommends: git
Recommends: subversion but it is not going to be installed
Recommends: xterm
Recommends: g++ but it is not going to be installed
E: Unmet dependencies. Try ‘apt –fix-broken install’ with no packages (or specify a solution).
chanmm@chanmm-Virtual-Machine:~$ apt –fix-broken install
E: Could not open lock file /var/lib/dpkg/lock-frontend – open (13: Permission denied)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root?
chanmm@chanmm-Virtual-Machine:~$ sudo -i
root@chanmm-Virtual-Machine:~# apt –fix-broken install
—————————————————————————————————————
In this case you need to run n superuser mode.
$ apt –fix-broken install
The re-run
$ sudo apt install build-essential
$ sudo apt-get install manpages-dev
I use gedit to paste and save the follow code.
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector<int> g1;
for (int i = 1; i <= 5; i++)
g1.push_back(i);
cout << “Output of begin and end: “;
for (auto i = g1.begin(); i != g1.end(); ++i)
cout << *i << ” “;
cout << “\nOutput of cbegin and cend: “;
for (auto i = g1.cbegin(); i != g1.cend(); ++i)
cout << *i << ” “;
cout << “\nOutput of rbegin and rend: “;
for (auto ir = g1.rbegin(); ir != g1.rend(); ++ir)
cout << *ir << ” “;
cout << “\nOutput of crbegin and crend : “;
for (auto ir = g1.crbegin(); ir != g1.crend(); ++ir)
cout << *ir << ” “;
return
0;
}
It is running fine.

Reference: https://chanmingman.wordpress.com/2020/11/08/microsoft-c-c-and-assembler-documentation/
https://docs.microsoft.com/en-us/cpp/?view=msvc-160/?WT.mc_id=DP-MVP-36769

























