standard-library-in-x

Notes and readings for STL workshop

View on GitHub

Introduction

Switching from Turbo to Gcc

Many institutions introduce programming to students by making them use Turbo compiler. While the interface of Turbo compiler might give you (a beginner) an amazing feeling that you are writing a code, that’s all it does. Turbo C++ uses a very old compiler which is outdated and is not in compliance with the latest standards, while the latest compilers are 32-bit or 64-bit and comply to the standards. If you haven’t already, it’s the right time to switch from TurboC++ to the worldwide used standard compiler like gcc/g++ or mingw-g++/mingw-gcc. We will cut to the chase by stating most important and valuable features of GCC:

Turbo V/s Gcc

While gcc is extensively used in Linux, mingw-gcc is the Windows version of gcc. Although it’s best to code in Linux, but if you’re more comfortable with Windows, it is recommended that you use replit. Repl.it is an online compiler (available at https://repl.it/), which supports many languages include c,c++,java,python etc.

Installation and Use

Gcc is preinstalled in any unix based system. To invoke gcc to compile C++ files, “g++” command is used. In Windows 10, one can enable the ubuntu unix terminal by enabling the developer mode in settings. Say you have a file helloworld.cpp as follows :

#include <cstdio>
#include <iostream>
using namespace std;
int main ()
{
    cout<<"Hello World"<<endl;
    return 0;
}

You can compile and run it from the unix prompt as follows :

g++ helloworld.cpp

This creates an executable called “a.out”. You can run it by typing

./a.out

Since no executable name was specified to g++, a.out is chosen by default. Use the -o option to change the name:

g++ helloworld.cpp -o helloworld

creates an executable called “helloworld”.

Points to Remember regarding GCC

#include<cmath>
#include<cstring>
#include<cstdio>
#include<ctime>
#include<cstdlib>
#include<cctype>