📅 Date: Jan 1, 2026
🔥 Topic: C++ Basics, Boilerplate, Input/Output
🚀 What is C++?
Today, I started my journey with C++. It is one of the most powerful, high-performance programming languages used for everything from Game Development to System Programming. It's a compiled language, meaning the code is translated into machine code before running, making it super fast.
🛠️ The Boilerplate (The Skeleton)
Every C++ program needs a basic structure to run. This is called the Boilerplate. Without this, the compiler won't know where to start.
#include <iostream> // 1. Header File
using namespace std; // 2. Standard Namespace
int main() { // 3. Main Function (Entry Point)
// Code goes here...
return 0; // 4. Exit Status
}
Breakdown:
1.#include <iostream>: Brings in input/output functionality.
2.using namespace std;: Helps us use standard commands like 'cout' directly.
3.int main(): This is where the execution begins.
4.return 0;: Tells the OS that the program ended successfully.
💻 How to Print Output (cout)
To display something on the screen, we use cout (Character Output) combined with insertion operators <<.
cout << "Hello World!" << endl;
Note: endl is used to move to a new line.
⌨️ How to Take User Input (cin)
To take data from the user, we use cin (Character Input) with extraction operators >>.
int age;
cin >> age;
⚡ Day 1: Full Code Snippet
Putting it all together, here is the first program I wrote today. It takes the user's name and goal, then prints it back.
#include <iostream>
using namespace std;
int main() {
// Variable Declaration
string name;
int goalYear;
// Output
cout << "Enter your name: ";
// Input
cin >> name;
cout << "Enter your target year: ";
cin >> goalYear;
// Final Output
cout << "-------------------------" << endl;
cout << "User: " << name << endl;
cout << "Mission Deadline: " << goalYear << endl;
cout << "Let's grind!" << endl;
return 0;
}
💠Thoughts
The logic is similar to other languages, but C++ feels much more closer to the hardware. Understanding cin and cout is just the start. Tomorrow, I will dive into Variables and Data Types in depth.
No comments:
Post a Comment