mirror of
https://github.com/kamranahmedse/developer-roadmap.git
synced 2025-08-29 20:21:50 +02:00
Corrected / Improved C++ roadmap (#5947)
Updated c++ content with `std::` as this is the recommended method. Added content links where needed and corrected various wording and grammar.
This commit is contained in:
@@ -2,9 +2,9 @@
|
||||
Before you can start programming in C++, you will need to have a compiler installed on your system. A compiler is a program that converts the C++ code you write into an executable file that your computer can run. There are several popular C++ compilers to choose from, depending on your operating system and preference.
|
||||
|
||||
### Windows
|
||||
For Windows, one popular option is to install the [Microsoft Visual Studio IDE](https://visualstudio.microsoft.com/vs/), which includes the Microsoft Visual C++ compiler.
|
||||
For Windows, one popular option is to install the [Microsoft Visual Studio IDE](https://visualstudio.microsoft.com/vs/), which includes the Microsoft Visual C++ compiler (MSVC).
|
||||
|
||||
Alternatively, you can also install the [MinGW-w64](https://mingw-w64.org/) compiler, which is a Windows port of the GNU Compiler Collection (GCC). To install MinGW-w64, follow these steps:
|
||||
Alternatively, you can also install the [MinGW-w64](https://mingw-w64.org/) compiler system, which is a Windows port of the GNU Compiler Collection (GCC). To install MinGW-w64, follow these steps:
|
||||
|
||||
- Download the installer from [here](https://sourceforge.net/projects/mingw-w64/files/).
|
||||
- Run the installer and select your desired architecture, version, and install location.
|
||||
|
@@ -1,8 +1,10 @@
|
||||
# Code Editors
|
||||
|
||||
Code editors are programs specifically designed for editing, managing and writing source code. They offer a wide range of features that make the development process easier and faster. Here's a brief introduction to some of the most popular code editors for C++:
|
||||
Code editors and IDEs are programs specifically designed for editing, managing and writing source code. They offer a wide range of features that make the development process easier and faster. Here's a brief introduction to some of the most popular code editors and IDEs for C++:
|
||||
|
||||
- **Visual Studio Code (VSCode)**: Visual Studio Code is a popular, free, open-source, and lightweight code editor developed by Microsoft. It has built-in support for C++, along with an extensive library of extensions and plugins.
|
||||
- **Visual Studio**: Visual Studio is an Integrated Development Environment (IDE) for Windows, developed by Microsoft. It includes its own integrated compiler known as Microsoft Visual C++ (MSVC).
|
||||
|
||||
- **Visual Studio Code (VSCode)**: Visual Studio Code is a popular, free, open-source, and lightweight code editor developed by Microsoft. It offers an extensive library of extensions that enhance functionality for C++ development.
|
||||
|
||||
- **Sublime Text**: Sublime Text is a cross-platform text editor that is quite popular among developers due to its speed and minimalist design. It supports C++ with the help of plugins and has a variety of themes and packages available for customization.
|
||||
|
||||
|
@@ -6,9 +6,8 @@ Setting up C++ requires a few steps, including installing a compiler, configurin
|
||||
|
||||
A compiler is required to convert C++ code into machine language. Some popular C++ compilers include:
|
||||
|
||||
- GCC (GNU Compiler Collection) for Linux and macOS
|
||||
- MinGW (Minimalist GNU for Windows) for Windows
|
||||
- Microsoft Visual C++ for Windows
|
||||
- GCC (GNU Compiler Collection) for Linux and macOS, but can also be used on Windows through MinGW
|
||||
- MSVC (Microsoft Visual C++) for Windows
|
||||
|
||||
To install a compiler, simply follow the instructions provided by the respective websites.
|
||||
|
||||
@@ -54,4 +53,4 @@ Setting up C++ involves:
|
||||
- Configuring an IDE (e.g. Visual Studio, Eclipse, or Code::Blocks)
|
||||
- Creating a new C++ project and writing code
|
||||
|
||||
By following these steps, you'll be ready to start developing C++ applications!
|
||||
By following these steps, you'll be ready to start developing C++ applications!
|
||||
|
@@ -13,7 +13,7 @@ C++ provides the following logical operators:
|
||||
```cpp
|
||||
int a = 5, b = 10;
|
||||
if (a > 0 && b > 0) {
|
||||
cout << "Both values are positive." << endl;
|
||||
std::cout << "Both values are positive." << std::endl;
|
||||
}
|
||||
```
|
||||
- **OR Operator (||)**
|
||||
@@ -25,7 +25,7 @@ C++ provides the following logical operators:
|
||||
```cpp
|
||||
int a = 5, b = -10;
|
||||
if (a > 0 || b > 0) {
|
||||
cout << "At least one value is positive." << endl;
|
||||
std::cout << "At least one value is positive." << std::endl;
|
||||
}
|
||||
```
|
||||
|
||||
@@ -38,7 +38,7 @@ C++ provides the following logical operators:
|
||||
```cpp
|
||||
int a = 5;
|
||||
if (!(a < 0)) {
|
||||
cout << "The value is not negative." << endl;
|
||||
std::cout << "The value is not negative." << std::endl;
|
||||
}
|
||||
```
|
||||
|
||||
@@ -48,8 +48,8 @@ Using these operators, you can create more complex logical expressions, for exam
|
||||
int a = 5, b = -10, c = 15;
|
||||
|
||||
if (a > 0 && (b > 0 || c > 0)) {
|
||||
cout << "At least two values are positive." << endl;
|
||||
std::cout << "At least two values are positive." << std::endl;
|
||||
}
|
||||
```
|
||||
|
||||
This covers the essential information about logical operators in C++.
|
||||
This covers the essential information about logical operators in C++.
|
||||
|
@@ -18,11 +18,10 @@ For example:
|
||||
|
||||
```cpp
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
for (int i = 0; i < 5; i++) {
|
||||
cout << "Iteration: " << i << endl;
|
||||
std::cout << "Iteration: " << i << std::endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -44,12 +43,11 @@ For example:
|
||||
|
||||
```cpp
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
int i = 0;
|
||||
while (i < 5) {
|
||||
cout << "Iteration: " << i << endl;
|
||||
std::cout << "Iteration: " << i << std::endl;
|
||||
i++;
|
||||
}
|
||||
return 0;
|
||||
@@ -72,12 +70,11 @@ For example:
|
||||
|
||||
```cpp
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
int i = 0;
|
||||
do {
|
||||
cout << "Iteration: " << i << endl;
|
||||
std::cout << "Iteration: " << i << std::endl;
|
||||
i++;
|
||||
} while (i < 5);
|
||||
return 0;
|
||||
|
@@ -4,7 +4,7 @@ A **function** is a group of statements that perform a specific task, organized
|
||||
|
||||
There are mainly two types of functions in C++:
|
||||
|
||||
- **Standard library functions**: Pre-defined functions available in the C++ standard library, such as `printf()`, `scanf()`, `sqrt()`, and many more. These functions are part of the standard library, so you need to include the appropriate header file to use them.
|
||||
- **Standard library functions**: Pre-defined functions available in the C++ standard library, such as `sort()`, `strlen()`, `sqrt()`, and many more. These functions are part of the standard library, so you need to include the appropriate header file to use them.
|
||||
|
||||
- **User-defined functions**: Functions created by the programmer to perform a specific task. To create a user-defined function, you need to define the function and call it in your code.
|
||||
|
||||
@@ -20,13 +20,12 @@ return_type function_name(parameter list) {
|
||||
|
||||
- `return_type`: Data type of the output produced by the function. It can be `void`, indicating that the function doesn't return any value.
|
||||
- `function_name`: Name given to the function, following C++ naming conventions.
|
||||
- `parameter list`: List of input parameters/arguments that are needed to perform the task. It is optional, and when no parameters are needed, you can leave it blank or use the keyword `void`.
|
||||
- `parameter list`: List of input parameters/arguments that are needed to perform the task. It is optional, you can leave it blank when no parameters are needed.
|
||||
|
||||
## Example
|
||||
|
||||
```cpp
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
// Function to add two numbers
|
||||
int addNumbers(int a, int b) {
|
||||
@@ -37,7 +36,7 @@ int addNumbers(int a, int b) {
|
||||
int main() {
|
||||
int num1 = 5, num2 = 10;
|
||||
int result = addNumbers(num1, num2); // Calling the function
|
||||
cout << "The sum is: " << result << endl;
|
||||
std::cout << "The sum is: " << result << std::endl;
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
@@ -52,7 +51,6 @@ A function prototype is a declaration of the function without its body, and it i
|
||||
|
||||
```cpp
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
// Function prototype
|
||||
int multiplyNumbers(int x, int y);
|
||||
@@ -60,7 +58,7 @@ int multiplyNumbers(int x, int y);
|
||||
int main() {
|
||||
int num1 = 3, num2 = 7;
|
||||
int result = multiplyNumbers(num1, num2); // Calling the function
|
||||
cout << "The product is: " << result << endl;
|
||||
std::cout << "The product is: " << result << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -75,4 +73,4 @@ In this example, we use a function prototype for `multiplyNumbers()` before defi
|
||||
|
||||
Learn more from the following resources:
|
||||
|
||||
- [@article@introduction to functions in c++](https://www.learncpp.com/cpp-tutorial/introduction-to-functions/)
|
||||
- [@article@introduction to functions in c++](https://www.learncpp.com/cpp-tutorial/introduction-to-functions/)
|
||||
|
@@ -90,7 +90,7 @@ Structures are used to store different data types under a single variable and ac
|
||||
Example:
|
||||
```cpp
|
||||
struct Person {
|
||||
string name;
|
||||
std::string name;
|
||||
int age;
|
||||
float height;
|
||||
};
|
||||
@@ -105,11 +105,11 @@ Example:
|
||||
```cpp
|
||||
class Person {
|
||||
public:
|
||||
string name;
|
||||
std::string name;
|
||||
int age;
|
||||
|
||||
void printInfo() {
|
||||
cout << "Name: " << name << ", Age: " << age << endl;
|
||||
std::cout << "Name: " << name << ", Age: " << age << std::endl;
|
||||
};
|
||||
};
|
||||
|
||||
|
@@ -14,10 +14,10 @@ You can use the reference just like you'd use the original variable. When you ch
|
||||
|
||||
```cpp
|
||||
var = 20; // Sets the value of var to 20
|
||||
cout << ref << endl; // Outputs 20
|
||||
std::cout << ref << std::endl; // Outputs 20
|
||||
|
||||
ref = 30; // Sets the value of ref to 30
|
||||
cout << var << endl; // Outputs 30
|
||||
std::cout << var << std::endl; // Outputs 30
|
||||
```
|
||||
|
||||
## Function Parameters
|
||||
@@ -31,9 +31,9 @@ void swap(int& a, int& b) {
|
||||
|
||||
int main() {
|
||||
int x = 5, y = 10;
|
||||
cout << "Before Swap: x = " << x << " y = " << y << endl; // Outputs 5 10
|
||||
std::cout << "Before Swap: x = " << x << " y = " << y << std::endl; // Outputs 5 10
|
||||
|
||||
swap(x, y);
|
||||
cout << "After Swap: x = " << x << " y = " << y << endl; // Outputs 10 5
|
||||
std::cout << "After Swap: x = " << x << " y = " << y << std::endl; // Outputs 10 5
|
||||
}
|
||||
```
|
||||
```
|
||||
|
@@ -10,18 +10,17 @@ Here's an example illustrating function overloading:
|
||||
|
||||
```cpp
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
void print(int num) {
|
||||
cout << "Printing int: " << num << endl;
|
||||
std::cout << "Printing int: " << num << std::endl;
|
||||
}
|
||||
|
||||
void print(double num) {
|
||||
cout << "Printing double: " << num << endl;
|
||||
std::cout << "Printing double: " << num << std::endl;
|
||||
}
|
||||
|
||||
void print(char const *str) {
|
||||
cout << "Printing string: " << str << endl;
|
||||
std::cout << "Printing string: " << str << std::endl;
|
||||
}
|
||||
|
||||
int main() {
|
||||
@@ -43,4 +42,4 @@ Printing double: 3.14
|
||||
Printing string: Hello, world!
|
||||
```
|
||||
|
||||
Keep in mind that the number of parameters and their types should be different for two functions to be overloaded.
|
||||
Keep in mind that the number of parameters and their types should be different for two functions to be overloaded.
|
||||
|
@@ -39,12 +39,12 @@ try {
|
||||
throw "Division by zero not allowed!";
|
||||
} else {
|
||||
int result = num1 / num2;
|
||||
cout << "Result: " << result << endl;
|
||||
std::cout << "Result: " << result << std::endl;
|
||||
}
|
||||
}
|
||||
catch (const char* e) {
|
||||
cout << "Error: " << e << endl;
|
||||
std::cout << "Error: " << e << std::endl;
|
||||
}
|
||||
```
|
||||
|
||||
In summary, exception handling in C++ is a technique to handle runtime errors while maintaining the normal flow of the program. The `try`, `catch`, and `throw` keywords are used together to create the structure to deal with exceptions as they occur.
|
||||
In summary, exception handling in C++ is a technique to handle runtime errors while maintaining the normal flow of the program. The `try`, `catch`, and `throw` keywords are used together to create the structure to deal with exceptions as they occur.
|
||||
|
@@ -25,14 +25,14 @@ Example:
|
||||
```cpp
|
||||
// If-else statement
|
||||
if (age > 18) {
|
||||
cout << "You are eligible to vote.";
|
||||
std::cout << "You are eligible to vote.";
|
||||
} else {
|
||||
cout << "You are not eligible to vote.";
|
||||
std::cout << "You are not eligible to vote.";
|
||||
}
|
||||
|
||||
// For loop
|
||||
for (int i = 0; i < 5; i++) {
|
||||
cout << "Hello World!";
|
||||
std::cout << "Hello World!";
|
||||
}
|
||||
```
|
||||
|
||||
@@ -47,7 +47,7 @@ int add(int a, int b) {
|
||||
|
||||
int main() {
|
||||
int sum = add(10, 20);
|
||||
cout << "The sum is: " << sum;
|
||||
std::cout << "The sum is: " << sum;
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
@@ -61,7 +61,7 @@ Example:
|
||||
int marks[] = {90, 80, 95, 85};
|
||||
|
||||
// Vector
|
||||
vector<int> scores = {10, 20, 30, 40};
|
||||
std::vector<int> scores = {10, 20, 30, 40};
|
||||
```
|
||||
|
||||
## Pointers
|
||||
@@ -80,17 +80,17 @@ Example:
|
||||
```cpp
|
||||
// Structure
|
||||
struct Student {
|
||||
string name;
|
||||
std::string name;
|
||||
int age;
|
||||
};
|
||||
|
||||
// Class
|
||||
class Employee {
|
||||
public:
|
||||
string name;
|
||||
std::string name;
|
||||
int age;
|
||||
void displayInfo() {
|
||||
cout << "Name: " << name << "\nAge: " << age;
|
||||
std::cout << "Name: " << name << "\nAge: " << age;
|
||||
}
|
||||
};
|
||||
```
|
||||
@@ -103,14 +103,14 @@ Example:
|
||||
class Base {
|
||||
public:
|
||||
void display() {
|
||||
cout << "This is the base class.";
|
||||
std::cout << "This is the base class.";
|
||||
}
|
||||
};
|
||||
|
||||
class Derived : public Base {
|
||||
public:
|
||||
void display() {
|
||||
cout << "This is the derived class.";
|
||||
std::cout << "This is the derived class.";
|
||||
}
|
||||
};
|
||||
```
|
||||
@@ -124,8 +124,8 @@ try {
|
||||
// Code that might throw an exception
|
||||
int result = a / b;
|
||||
} catch (const exception &e) {
|
||||
cout << "Caught an exception: " << e.what();
|
||||
std::cout << "Caught an exception: " << e.what();
|
||||
}
|
||||
```
|
||||
|
||||
These are some of the key language concepts in C++, which will help you to understand the language better and develop efficient and maintainable applications.
|
||||
These are some of the key language concepts in C++, which will help you to understand the language better and develop efficient and maintainable applications.
|
||||
|
@@ -45,14 +45,13 @@ Example using GDB:
|
||||
// test.cpp
|
||||
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
int num1 = 10;
|
||||
int num2 = 0;
|
||||
int result = num1 / num2;
|
||||
|
||||
cout << "Result: " << result << endl;
|
||||
std::cout << "Result: " << result << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -72,4 +71,4 @@ Program received signal SIGFPE, Arithmetic exception.
|
||||
7 int result = num1 / num2;
|
||||
```
|
||||
|
||||
Now you can make appropriate changes to fix the issue in your C++ code.
|
||||
Now you can make appropriate changes to fix the issue in your C++ code.
|
||||
|
@@ -28,7 +28,6 @@ Here's an example demonstrating an HTTP client using the Poco library:
|
||||
|
||||
using namespace Poco::Net;
|
||||
using namespace Poco;
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
@@ -45,22 +44,24 @@ int main()
|
||||
|
||||
// Process the response
|
||||
HTTPResponse response;
|
||||
istream& responseStream = session.receiveResponse(response);
|
||||
std::istream& responseStream = session.receiveResponse(response);
|
||||
if (response.getStatus() == HTTPResponse::HTTP_OK)
|
||||
{
|
||||
// Successful
|
||||
std::string responseBody;
|
||||
StreamCopier::copyToString(responseStream, responseBody);
|
||||
cout << "Response: " << responseBody << endl;
|
||||
|
||||
std::cout << "Response: " << responseBody << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Error
|
||||
cout << "Error: " << response.getStatus() << " " << response.getReason() << endl;
|
||||
std::cout << "Error: " << response.getStatus() << " " << response.getReason() << std::endl;
|
||||
}
|
||||
}
|
||||
catch(const Exception& e)
|
||||
{
|
||||
cerr << "Error: " << e.displayText() << endl;
|
||||
std::cerr << "Error: " << e.displayText() << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user