Table of Contents
Using an IDEUsing Command LineText EditorsSublime Text Notes (Ben)Further InstructionsIncludingRunning Code Locally
Authors: Benjamin Qi, Hankai Zhang, Anthony Wang, Nathan Wang, Nathan Chen, Owen Wang, Shourya Bansal
Prerequisites
Options for running your language of choice locally.
Table of Contents
Using an IDEUsing Command LineText EditorsSublime Text Notes (Ben)Further InstructionsIncludingEdit with LiveUpdate
Which text editor or IDE should I use?
Depends on your personal preference. Try multiple and see which one you like best.
If you're just starting out, it's easier to begin by running code online and worry about running locally later. You can find more information about running code online here.
Using an IDE
Resources | |||
---|---|---|---|
IOI | for reference, software you can use at IOI |
Please let us know if you have trouble with installation!
C++
Resources | |||
---|---|---|---|
Geany | Lightweight, frequently used at IOI. | ||
Microsoft | More lightweight than Visual Studio Community, requires some configuration. See PAPS 2.1 and the docs for C++ setup instructions. | ||
Code::Blocks | Windows & Linux. Apparently was unstable at IOI. | ||
Apple | Mac. | ||
Jetbrains | Requires a license, but free for students. |
Java
It can be useful to use a Java IDE to take advantage of the powerful debugging features in Java.
Resources | |||
---|---|---|---|
JetBrains | free | ||
Eclipse Foundation | free | ||
King's College London | free |
Python
Python comes with a program, known as IDLE (Integrated Development and Learning Environment), that allows one to write and run Python code. It supports many features, such as syntax highlighting and automatic indentation, that one would normally expect from an IDE/text editor. However, feel free to use another editor or IDE if you want to.
Using Command Line
C++
You can run your C++ programs from the command line and use a text editor of your choice.
Text Editors
Resources | |||
---|---|---|---|
Fast, lightweight. Unlimited free evaluation period, though it will repeatedly ask you to purchase a license. | |||
Classic text editor, usually preinstalled on Linux. Also see Neovim, MacVim | |||
From the makers of Github. |
Vim is probably the easiest way to print syntax-highlighted code on Mac, see the response to this post.
Sublime Text Notes (Ben)
- I prefer the Mariana color scheme in place of the default.
- open command palette (Cmd-Shift-P) -> change color scheme
subl
symlink- Using
/usr/local/bin/subl
instead of~/bin/subl
worked for me on OS X Mojave.
- Using
- Package - Sublime Linter (GCC)
- highlights compilation errors and warnings from
-Wall
- can change compilation commands in
linter.py
- highlights compilation errors and warnings from
- Package - Fast Olympic Coding (I don't use)
- test manager can be useful
- linting is covered by the above
- stress testing is covered in Debugging
- can't get debug to work
Further Instructions
See this module for information about installing, compiling, and running C++ from the command line.
Including <bits/stdc++.h>
You can use #include <bits/stdc++.h>
in place of separately including libraries.
Usage
This is usable with GCC. However, Mac OS X uses Clang while Windows uses Microsoft Visual C++ (MVSC) by default. <bits/stdc++.h>
is not a standard header file, so it will not work with the latter two. This is one of the reasons why you should not use <bits/stdc++.h>
outside of competitive programming.
Resources | |||
---|---|---|---|
SO | wow, people are really mad about this! | ||
SO |
If you install GCC as described later in the module linked above, then you should be good to go.
OS-Specific Recommendations
This section is not complete.
Linux
Windows
With the variety of software available for Windows, deciding what to use can be difficult. While the most popular options are Visual Studio Code, Geany, and CodeBlocks, any text editor or IDE that you feel comfortable using (as long as it works with C++) will work.
To get the full functionality of C++ on your Windows Machine, you should install one of the following compilers, from easiest to most difficult to set up and use:
Simple: MinGW (Minimalist GNU for Windows)
If you want to keep the ease of use and simplicity of Linux C++, including the ability to use commands like g++
and easily include <bits/stdc++.h>
, you can install the compiler MinGW. This is a version of the g++
compiler from Linux available on Windows. If you are using VS Code, setting up MinGW can be more difficult, but there are great guides to make the process easier.
Resources | |||
---|---|---|---|
MinGW | The Official MinGW Installer | ||
Microsoft | Microsoft's Simpler MinGW Installer | ||
Microsoft | Setting Up MinGW with VS Code | ||
Jetbrains | Setting up MinGW with CLion |
Depending on the installer you used, installing MinGW could be a little complicated.
The Official Installer:
- First, download and run the MinGW installer.
- Once it's installed, open the MinGW Installation Manager, click on Basic Setup on the left, and select
mingw32-gcc-g++-bin
for installation. - Finally, Add it to your PATH following the latter half of this tutorial
Microsoft's Mirror Installer:
- First, download the installer
- When you run it, leave all settings at default except
Architecture
.- For
Architecture
, selectx86_64
.
- After you click next, copy the
Destination Folder Path
for later and finish the installation. - Now, you need to add MinGW to your
Path
. To do that:- After the Installation has completed, search for
Environmental Variables
in the Windows Search Bar and click open - Click the button
Environment Variables
at the bottom left. - In the bottom half of the screen (under
System variables
), find the keyPath
and double click. - Click
New
on the top right and paste the path you copied. Add\bin
to the end of it. It should look something like this:C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin
- You're Good to Go!
Moderate: Microsoft Compiler Toolset
Microsoft's Visual C++ Compiler is the official compiler for compiling programs for Windows and can be installed either via installing the relevant packages with Visual Studio 2019 or the build tools from their website. More information on its installation can be found in their documentation.
Resources | |||
---|---|---|---|
Microsoft | The Visual Studio Documentation |
In order to get a similar library to <bits/stdc++.h>
you can use the following template, which automatically swaps between <bits/stdc++.h>
and Microsoft's variant depending on the system running it:
#ifdef _WIN32#include <__msvc_all_public_headers.hpp>#endif#ifdef __linux__#include <bits/stdc++.h>#endifusing namespace std;
This checks if the compiler is compiling for windows (your local machine) or if it is compiling for the remote judge and subsequently includes the correct libraries for the system. This comes with the same consequences as using <bits/stdc++.h>
for the same reasons.
Note: As USACO has now disallowed the use of templates during competitions, if you want to be able to get the functionality of <bits/stdc++.h>
on your local machine, you should use MinGW instead.
Difficult: Windows Subsystem for Linux (WSL)
If you're already accustomed to the Linux Command line, this might be the best option for you.
Windows Subsystem for Linux, commonly referred to as WSL, runs the linux kernel (or an emulation layer, depending on which version you use) within you windows installation. This allows you to use Linux binaries without needing to use Linux as your main Operating System, meaning that you can install g++
, use g++
, and consequently include <bits/stdc++.h>
in your Competitive Programming C++ files.
Many people use WSL (such as Anthony), but it can be difficult to properly set up.
Resources | |||
---|---|---|---|
Microsoft | difficult for beginners |
If you want to code in (neo)vim, you can install WSL and code through WSL bash.
To install the necessary tools after setting up WSL, you can run the following commands.
On Debian based distributions like Ubuntu:
sudo apt-get install build-essential
On Arch based distributions like Arch Linux:
sudo pacman -Sy base-devel
You can find many tutorials on how to style up WSL and make it feel more cozy. The first step is to use a proper terminal and not the default one that Windows provides. An easy to use option is Windows Terminal, which can be found on the Microsoft Store.
Resources | |||
---|---|---|---|
Setting up your terminal | |||
Get a beautiful command line interface |
Mac
XCode?
Using <bits/stdc++.h>
Without Installing GCC
If you installed Clang on Mac, then you can download stdc++.h
from here and move it into a folder named bits
that is located in the same directory as where all other C++ header files are located. However, this is not recommended.
Resources | |||
---|---|---|---|
SO | solutions that may or may not work |
Java
Installation
Linux
First, you can check if you have Java already installed by running java --version
in the terminal. If it returns something like this:
openjdk 11.0.9.1 2020-11-04 OpenJDK Runtime Environment (build 11.0.9.1+1-Ubuntu-0ubuntu1.20.04) OpenJDK 64-Bit Server VM (build 11.0.9.1+1-Ubuntu-0ubuntu1.20.04, mixed mode, sharing)
That means you have Java installed already. On the other hand, if you get something like this:
Command 'java' not found
You will have to download and install JDK. On most Linux distros, the JDK can be downloaded via the built in package manager.
Ubuntu/Debian
On Ubuntu, Debian, and other Ubuntu/Debian based distos, the JDK can be installed via apt
. You can install the Java JDK from the default repositories by running: sudo apt install default-jdk
.
After this finishes installing, if you run java --version
again, you should get something like above.
Arch
On Arch and other Arch based distos (like Manjaro), the JDK can be installed via pacman
. You can install the Java JDK from the default repositories by running: sudo pacman -S jdk-openjdk
.
After this finishes installing, if you run java --version
again, you should get something like above.
Fedora
On Fedora and other Red Hat based distos, the JDK can be installed via dnf
. You can install the Java JDK from the default repositories by running: sudo dnf install java-openjdk-devel.x86_64
.
After this finishes installing, if you run java --version
again, you should get something like above.
Windows
First, can check if you already have Java installed by running java --version
in cmd
. If it returns something like this:
openjdk 11.0.9.1 2020-11-04 OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.9.1+1) OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.9.1+1, mixed mode)
That means that you have Java installed already. On the other hand, if you get something like this:
'java' is not recognized as an internal or external command, operable program or batch file.
You will have to download and install JDK from here.
After it finishes installing, if you run java --version
again, you should get something like above. Note: the installer should automatically add Java into the system PATH
, but in the event that it doesn't, you can find more information on how to do that here.
macOS
First, can check if you already have Java installed by running java --version
in the terminal. If it returns something like this:
openjdk 11.0.9.1 2020-11-04 OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.9.1+1) OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.9.1+1, mixed mode)
That means that you have Java installed already. On the other hand, if you get something like this:
-bash: java: command not found
You will have to download and install JDK from here.
After it finishes installing, if you run java --version
again, you should get something like above.
Compiling and Running
Running a Java file off of the command-line is relatively simple after the JDK is downloaded.
Consider this code of Main.java
and assume it is in a file on your computer:
public class Main {public static void main(String[] args) {System.out.println("Hello World!");}}
Use the cd
command on your console to get to the directory that contains Main.java
. Then, run the following command to compile the code:
javac Main.java
If it runs successfully, a file called Main.class
will show up in the same directory, which can be executed with the next command:
java Main
If everything goes accordingly, the console should output Hello World!
.
If you do USACO-style file I/O, meaning that files are in the "local directory", then the files must be located in the same directory as the source code (if you use the above method). You can find a Java testing script for USACO here.
Python
Download Python through the official website. On Windows and Mac, you can download executable files directly; on Linux, you must either download the Python source code and compile from source, or obtain Python through your package manager.
Make sure that you are using the correct version of Python. Python 2 is quite different from Python 3 (but parts of the version number beyond 2. or 3. do not matter much). We generally recommend newcomers to use Python 3, but if you are used to programming in Python 2, that is OK too.
The Python version can matter when using the command line to run Python; sometimes, python3
must be used instead of python
in order to run Python 3. Try both commands, and pay attention to the version that Python prints to determine if this is the case on your system. For example, running the following in Terminal on my computer produces:
python --version # prints Python 2.7.13 python3 --version # prints Python 3.8.1
Module Progress:
Join the USACO Forum!
Stuck on a problem, or don't understand a module? Join the USACO Forum and get help from other competitive programmers!