-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCpp1_1.html
More file actions
108 lines (92 loc) · 3.78 KB
/
Copy pathCpp1_1.html
File metadata and controls
108 lines (92 loc) · 3.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<article>
<h1>C++ I: Page 1 - Introduction to C++ and the Development Environment</h1>
<section>
<h2>What is C++?</h2>
<p>C++ is a high-performance, compiled, object-oriented language that provides low-level memory manipulation features while maintaining high-level abstractions. It is the powerhouse behind operating systems, game engines, high-frequency trading platforms, and large-scale enterprise software.</p>
</section>
<section>
<h2>The C++ Development Pipeline & Project Setup</h2>
<p>Unlike Python, C++ must be compiled into machine code. A robust C++ environment involves understanding header files, source files, and the compilation process managed by a build system like CMake.</p>
<pre><code class="language-cpp">
/*
* File: main.cpp
* A comprehensive example demonstrating C++ project structure
*/
#include <iostream>
#include <string>
#include <vector>
#include <algorithm> // For modern algorithms
// Preprocessor definitions
#define MAX_BUFFER_SIZE 1024
#define VERSION "1.0.0"
// Namespace best practice
using namespace std;
// Structure to hold data
struct AppConfig {
string appName;
int timeout;
};
// Function prototypes
void InitializeEnvironment(AppConfig& config);
void ProcessTasks(const vector<string>& tasks);
int main() {
cout << "--- C++ Application Starting (v" << VERSION << ") ---" << endl;
AppConfig config;
InitializeEnvironment(config);
vector<string> tasks = {
"Parsing command line args",
"Loading configuration file",
"Initializing network interface",
"Establishing database connection"
};
ProcessTasks(tasks);
cout << "--- Initialization Complete (Timeout: "
<< config.timeout << "ms) ---" << endl;
return 0;
}
void InitializeEnvironment(AppConfig& config) {
config.appName = "EngineX";
config.timeout = 5000; // 5 seconds
cout << ">> Setting up environment for: " << config.appName << endl;
}
void ProcessTasks(const vector<string>& tasks) {
// Modern for-range loop
for (const auto& task : tasks) {
cout << ">> Executing: " << task << endl;
}
}
/*
* Compiling this requires a C++ compiler:
* g++ -std=c++17 main.cpp -o engine_x
*
* 1. Preprocessor: #include, #define replaced.
* 2. Compilation: Source -> Assembly -> Object (.o)
* 3. Linking: Object files + Libraries -> Executable
*/
// Memory management example (Pre-smart pointers)
void LegacyMemoryHandling() {
int* data = new int[MAX_BUFFER_SIZE];
// ... complex logic ...
delete[] data; // Crucial: Prevent memory leaks
}
</code></pre>
<div class="interactive-sim">
<h3>C++ Compilation Simulator</h3>
<button class="sim-button" onclick="
const out = document.getElementById('sim-output-cpp1_1');
out.innerHTML = 'g++ -std=c++17 main.cpp -o engine_x;<br>';
setTimeout(() => out.innerHTML += '>> Preprocessing...<br>', 400);
setTimeout(() => out.innerHTML += '>> Compiling...<br>', 800);
setTimeout(() => out.innerHTML += '>> Linking...<br>', 1200);
setTimeout(() => out.innerHTML += '>> Compilation Successful! Execution: EngineX v1.0.0', 1600);
">Run Simulation</button>
<div id="sim-output-cpp1_1" class="sim-output"></div>
</div>
</section>
<footer style="margin-top: 40px; padding: 20px; background: #f8f9fa; border-top: 1px solid #dee2e6;">
<div style="display: flex; justify-content: space-between;">
<span> </span>
<a href="#" data-file="Cpp1_2.html" style="font-weight: bold; text-decoration: none; color: #007bff;">Next: Variables & Primitives →</a>
</div>
</footer>
</article>