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.
pull/5969/head
fellalli 5 months ago committed by GitHub
parent 7d694f3e56
commit e4d106904e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 4
      src/data/roadmaps/cpp/content/101-setting-up/100-installing.md
  2. 6
      src/data/roadmaps/cpp/content/101-setting-up/101-code-editors.md
  3. 5
      src/data/roadmaps/cpp/content/101-setting-up/index.md
  4. 8
      src/data/roadmaps/cpp/content/102-basic-operations/101-logical-operators.md
  5. 9
      src/data/roadmaps/cpp/content/102-basic-operations/102-loops.md
  6. 10
      src/data/roadmaps/cpp/content/103-functions/index.md
  7. 6
      src/data/roadmaps/cpp/content/104-data-types/index.md
  8. 8
      src/data/roadmaps/cpp/content/105-pointers-and-references/100-references.md
  9. 7
      src/data/roadmaps/cpp/content/107-structures-and-classes/101-oop/100-static-polymorphism/overloading-functions.md
  10. 4
      src/data/roadmaps/cpp/content/108-exception-handling/100-exceptions/index.md
  11. 22
      src/data/roadmaps/cpp/content/109-language-concepts/index.md
  12. 3
      src/data/roadmaps/cpp/content/114-debuggers/100-debugger-messages.md
  13. 11
      src/data/roadmaps/cpp/content/libraries/102-poco.md

@ -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. 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 ### 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/). - Download the installer from [here](https://sourceforge.net/projects/mingw-w64/files/).
- Run the installer and select your desired architecture, version, and install location. - Run the installer and select your desired architecture, version, and install location.

@ -1,8 +1,10 @@
# Code Editors # 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. - **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: A compiler is required to convert C++ code into machine language. Some popular C++ compilers include:
- GCC (GNU Compiler Collection) for Linux and macOS - GCC (GNU Compiler Collection) for Linux and macOS, but can also be used on Windows through MinGW
- MinGW (Minimalist GNU for Windows) for Windows - MSVC (Microsoft Visual C++) for Windows
- Microsoft Visual C++ for Windows
To install a compiler, simply follow the instructions provided by the respective websites. To install a compiler, simply follow the instructions provided by the respective websites.

@ -13,7 +13,7 @@ C++ provides the following logical operators:
```cpp ```cpp
int a = 5, b = 10; int a = 5, b = 10;
if (a > 0 && b > 0) { if (a > 0 && b > 0) {
cout << "Both values are positive." << endl; std::cout << "Both values are positive." << std::endl;
} }
``` ```
- **OR Operator (||)** - **OR Operator (||)**
@ -25,7 +25,7 @@ C++ provides the following logical operators:
```cpp ```cpp
int a = 5, b = -10; int a = 5, b = -10;
if (a > 0 || b > 0) { 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 ```cpp
int a = 5; int a = 5;
if (!(a < 0)) { if (!(a < 0)) {
cout << "The value is not negative." << endl; std::cout << "The value is not negative." << std::endl;
} }
``` ```
@ -48,7 +48,7 @@ Using these operators, you can create more complex logical expressions, for exam
int a = 5, b = -10, c = 15; int a = 5, b = -10, c = 15;
if (a > 0 && (b > 0 || c > 0)) { 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;
} }
``` ```

@ -18,11 +18,10 @@ For example:
```cpp ```cpp
#include <iostream> #include <iostream>
using namespace std;
int main() { int main() {
for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) {
cout << "Iteration: " << i << endl; std::cout << "Iteration: " << i << std::endl;
} }
return 0; return 0;
} }
@ -44,12 +43,11 @@ For example:
```cpp ```cpp
#include <iostream> #include <iostream>
using namespace std;
int main() { int main() {
int i = 0; int i = 0;
while (i < 5) { while (i < 5) {
cout << "Iteration: " << i << endl; std::cout << "Iteration: " << i << std::endl;
i++; i++;
} }
return 0; return 0;
@ -72,12 +70,11 @@ For example:
```cpp ```cpp
#include <iostream> #include <iostream>
using namespace std;
int main() { int main() {
int i = 0; int i = 0;
do { do {
cout << "Iteration: " << i << endl; std::cout << "Iteration: " << i << std::endl;
i++; i++;
} while (i < 5); } while (i < 5);
return 0; 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++: 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. - **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. - `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. - `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 ## Example
```cpp ```cpp
#include <iostream> #include <iostream>
using namespace std;
// Function to add two numbers // Function to add two numbers
int addNumbers(int a, int b) { int addNumbers(int a, int b) {
@ -37,7 +36,7 @@ int addNumbers(int a, int b) {
int main() { int main() {
int num1 = 5, num2 = 10; int num1 = 5, num2 = 10;
int result = addNumbers(num1, num2); // Calling the function int result = addNumbers(num1, num2); // Calling the function
cout << "The sum is: " << result << endl; std::cout << "The sum is: " << result << std::endl;
return 0; return 0;
} }
``` ```
@ -52,7 +51,6 @@ A function prototype is a declaration of the function without its body, and it i
```cpp ```cpp
#include <iostream> #include <iostream>
using namespace std;
// Function prototype // Function prototype
int multiplyNumbers(int x, int y); int multiplyNumbers(int x, int y);
@ -60,7 +58,7 @@ int multiplyNumbers(int x, int y);
int main() { int main() {
int num1 = 3, num2 = 7; int num1 = 3, num2 = 7;
int result = multiplyNumbers(num1, num2); // Calling the function int result = multiplyNumbers(num1, num2); // Calling the function
cout << "The product is: " << result << endl; std::cout << "The product is: " << result << std::endl;
return 0; return 0;
} }

@ -90,7 +90,7 @@ Structures are used to store different data types under a single variable and ac
Example: Example:
```cpp ```cpp
struct Person { struct Person {
string name; std::string name;
int age; int age;
float height; float height;
}; };
@ -105,11 +105,11 @@ Example:
```cpp ```cpp
class Person { class Person {
public: public:
string name; std::string name;
int age; int age;
void printInfo() { 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 ```cpp
var = 20; // Sets the value of var to 20 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 ref = 30; // Sets the value of ref to 30
cout << var << endl; // Outputs 30 std::cout << var << std::endl; // Outputs 30
``` ```
## Function Parameters ## Function Parameters
@ -31,9 +31,9 @@ void swap(int& a, int& b) {
int main() { int main() {
int x = 5, y = 10; 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); 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 ```cpp
#include <iostream> #include <iostream>
using namespace std;
void print(int num) { void print(int num) {
cout << "Printing int: " << num << endl; std::cout << "Printing int: " << num << std::endl;
} }
void print(double num) { void print(double num) {
cout << "Printing double: " << num << endl; std::cout << "Printing double: " << num << std::endl;
} }
void print(char const *str) { void print(char const *str) {
cout << "Printing string: " << str << endl; std::cout << "Printing string: " << str << std::endl;
} }
int main() { int main() {

@ -39,11 +39,11 @@ try {
throw "Division by zero not allowed!"; throw "Division by zero not allowed!";
} else { } else {
int result = num1 / num2; int result = num1 / num2;
cout << "Result: " << result << endl; std::cout << "Result: " << result << std::endl;
} }
} }
catch (const char* e) { catch (const char* e) {
cout << "Error: " << e << endl; std::cout << "Error: " << e << std::endl;
} }
``` ```

@ -25,14 +25,14 @@ Example:
```cpp ```cpp
// If-else statement // If-else statement
if (age > 18) { if (age > 18) {
cout << "You are eligible to vote."; std::cout << "You are eligible to vote.";
} else { } else {
cout << "You are not eligible to vote."; std::cout << "You are not eligible to vote.";
} }
// For loop // For loop
for (int i = 0; i < 5; i++) { 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 main() {
int sum = add(10, 20); int sum = add(10, 20);
cout << "The sum is: " << sum; std::cout << "The sum is: " << sum;
return 0; return 0;
} }
``` ```
@ -61,7 +61,7 @@ Example:
int marks[] = {90, 80, 95, 85}; int marks[] = {90, 80, 95, 85};
// Vector // Vector
vector<int> scores = {10, 20, 30, 40}; std::vector<int> scores = {10, 20, 30, 40};
``` ```
## Pointers ## Pointers
@ -80,17 +80,17 @@ Example:
```cpp ```cpp
// Structure // Structure
struct Student { struct Student {
string name; std::string name;
int age; int age;
}; };
// Class // Class
class Employee { class Employee {
public: public:
string name; std::string name;
int age; int age;
void displayInfo() { void displayInfo() {
cout << "Name: " << name << "\nAge: " << age; std::cout << "Name: " << name << "\nAge: " << age;
} }
}; };
``` ```
@ -103,14 +103,14 @@ Example:
class Base { class Base {
public: public:
void display() { void display() {
cout << "This is the base class."; std::cout << "This is the base class.";
} }
}; };
class Derived : public Base { class Derived : public Base {
public: public:
void display() { void display() {
cout << "This is the derived class."; std::cout << "This is the derived class.";
} }
}; };
``` ```
@ -124,7 +124,7 @@ try {
// Code that might throw an exception // Code that might throw an exception
int result = a / b; int result = a / b;
} catch (const exception &e) { } catch (const exception &e) {
cout << "Caught an exception: " << e.what(); std::cout << "Caught an exception: " << e.what();
} }
``` ```

@ -45,14 +45,13 @@ Example using GDB:
// test.cpp // test.cpp
#include <iostream> #include <iostream>
using namespace std;
int main() { int main() {
int num1 = 10; int num1 = 10;
int num2 = 0; int num2 = 0;
int result = num1 / num2; int result = num1 / num2;
cout << "Result: " << result << endl; std::cout << "Result: " << result << std::endl;
return 0; return 0;
} }

@ -28,7 +28,6 @@ Here's an example demonstrating an HTTP client using the Poco library:
using namespace Poco::Net; using namespace Poco::Net;
using namespace Poco; using namespace Poco;
using namespace std;
int main() int main()
{ {
@ -45,22 +44,24 @@ int main()
// Process the response // Process the response
HTTPResponse response; HTTPResponse response;
istream& responseStream = session.receiveResponse(response); std::istream& responseStream = session.receiveResponse(response);
if (response.getStatus() == HTTPResponse::HTTP_OK) if (response.getStatus() == HTTPResponse::HTTP_OK)
{ {
// Successful // Successful
std::string responseBody;
StreamCopier::copyToString(responseStream, responseBody); StreamCopier::copyToString(responseStream, responseBody);
cout << "Response: " << responseBody << endl;
std::cout << "Response: " << responseBody << std::endl;
} }
else else
{ {
// Error // Error
cout << "Error: " << response.getStatus() << " " << response.getReason() << endl; std::cout << "Error: " << response.getStatus() << " " << response.getReason() << std::endl;
} }
} }
catch(const Exception& e) catch(const Exception& e)
{ {
cerr << "Error: " << e.displayText() << endl; std::cerr << "Error: " << e.displayText() << std::endl;
return -1; return -1;
} }

Loading…
Cancel
Save