This repo can be used for educational purpose only. Please don't copy/pase the code directly to URI. After trying the problem yourself if you can't solve that problem then you can check my solutions.
## VSCode Tasks for C++ Compilation and Execution
This project uses a `tasks.json` file in Visual Studio Code to streamline the process of compiling and running C++ programs. Below is a breakdown of the tasks and how to use them.
## Prerequisites
- **g++**: Ensure that `g++` is installed on your system to compile C++ programs.
You can install it using the following command:
```bash
sudo apt install g++
```-
Visual Studio Code: You should have VSCode installed with the C++ extensions for syntax highlighting and better development experience.
-
input.txt: This file should exist in the same directory as your C++ file if you want to redirect input during execution.
The tasks.json provides two tasks: one for compiling the C++ code, and another for compiling and running it in one step.
-
Label:
compile -
Command: This task compiles the currently open C++ file using the following command:
g++ -std=c++17 -o <filename without extension> <file path>
- Input: The open C++ file in the editor.
- Output: An executable file with the same name as the C++ source file (but without the
.cppextension).
- Open your
.cppfile in VSCode. - Press
Ctrl+Shift+Band select thecompiletask. - The compiled executable will be created in the same directory as your source file.
-
Label:
compile and run -
Command: This task compiles and then runs the program, redirecting input from
input.txtand outputting tooutput.txt.g++ -std=c++17 -o <filename without extension> <file path> && ./<filename without extension> < input.txt > output.txt
- Input: The currently open
.cppfile in the editor, andinput.txtif present. - Output: The output will be saved to
output.txtin the same directory as the C++ file.
- Input: The currently open
- Open your
.cppfile in VSCode. - Make sure you have an
input.txtfile in the same directory. - Press
Ctrl+Shift+Band select thecompile and runtask. - The program will be compiled and executed, with input read from
input.txtand output written tooutput.txt.
- File Paths: This
tasks.jsonfile handles file paths with spaces (e.g., directories likeProgramming for Career), so ensure that your project files are structured correctly. - Input/Output Redirection: The program expects
input.txtto be present for input redirection. You can modify the task for different input/output needs.
- No such file or directory: Ensure that the paths in the
input.txtandoutput.txtfiles are correct. - Compile Errors: Check that your C++ code does not contain syntax errors by looking at the terminal output when running the
compiletask.