Arrays | Sololearn: Learn to code for FREE!



How do I compile an array using gnu ?


4/14/2018 8:37:17 PM

Thizwilondi Nembahe

3 Answers

New Answer


The base command for the Gnu C++ compiler is "g++" For single file programs, the easiest compilation uses the command format: g++ <filename> (where the filename ends with ".cpp"). Example: g++ prog1.cpp will compile a c++ code called prog1.cpp I tend to add -Wall to look at all warnings, but that's up to you. There's other flags like debugging, optimizations, and more This command will create an executable program called "a.out" (the default executable target name when one is not specified).


g++ your_file.cpp Where your_file.cpp contains code doing something with an array.


I recommend: g++ code.cpp -Wall -o code && ./code Where "code" is the program name. It will compile and run like an IDE then. To automate this you could save this script: #! /bin/sh g++ $1 -Wall -o $(echo $1 | sed 's/.cpp//') && ./$(echo $1 | sed 's/.cpp//') Save that as say "compile", then do "chmod +x compile". Now you can type: ./compile file.cpp to compile and run the file. PS: I know the script was a little messy \_O_/