EZ Notes Logo

EZNotes

🎯 Aim

To write, save, and run your first C/C++ program using Visual Studio Code.

🛠️ What You Need

  • Visual Studio Code installed on your computer
  • C/C++ extension installed in VS Code
  • MinGW or any C/C++ compiler installed

📖 Introduction

C and C++ are popular programming languages. They are used to make games, apps, and software. In this practical, you will learn how to write a simple "Hello World" program in C/C++ using VS Code. This is the first program that every programmer writes!

📝 Steps

Step 1: Open VS Code

  1. Click the VS Code icon on your desktop or Start Menu.
  2. Wait for VS Code to open.

Step 2: Create a New File

  1. Click the Explorer icon (the first icon on the left side).
  2. Click "Open Folder" and create a new folder called "MyPrograms".
  3. Click the New File button (the page icon with a plus sign).
  4. Type the file name: hello.cpp and press Enter.
VS Code New File Figure 1: Creating a New File in VS Code

Step 3: Write the Code

  1. Copy and paste the code below into the file.
// My first C++ program #include <iostream> using namespace std; int main() { cout << "Hello World!" << endl; cout << "Welcome to C++ Programming" << endl; return 0; }
C++ Code in VS Code Figure 2: Writing Code in VS Code

Step 4: Save the File

  1. Press Ctrl + S (Windows) or Cmd + S (Mac) to save the file.
  2. You will see the file name hello.cpp in the Explorer.

Step 5: Run the Program

  1. Click the Run menu at the top.
  2. Click "Run Without Debugging" (or press Ctrl + F5).
  3. If asked to choose a compiler, select g++ or gcc.
  4. Your program will run and show the output in the terminal.
VS Code Output Figure 3: Program Output in VS Code Terminal

📊 Observations

  • A new file hello.cpp was created.
  • The code was written correctly.
  • The program compiled and ran successfully.
  • The output shows "Hello World!" and "Welcome to C++ Programming".

✅ Result

Your first C++ program was written, saved, and run successfully. You have learned how to create and execute a simple program in VS Code.

💡 Tip: Always save your file before running it. The extension .cpp is for C++ files. For C files, use .c.
📌 Important: Make sure you have the C/C++ extension installed in VS Code. You can install it from the Extensions tab (square icon on the left).

🎯 مقصد

Visual Studio Code کا استعمال کرتے ہوئے اپنا پہلا C/C++ پروگرام لکھنا، محفوظ کرنا اور چلانا۔

🛠️ آپ کو کیا چاہیے

  • آپ کے کمپیوٹر پر Visual Studio Code انسٹال ہو
  • VS Code میں C/C++ ایکسٹینشن انسٹال ہو
  • MinGW یا کوئی بھی C/C++ کمپائلر انسٹال ہو

📖 تعارف

C اور C++ مشہور پروگرامنگ زبانیں ہیں۔ یہ گیمز، ایپس اور سافٹ ویئر بنانے کے لیے استعمال ہوتی ہیں۔ اس عملی میں، آپ VS Code کا استعمال کرتے ہوئے C++ میں ایک سادہ "Hello World" پروگرام لکھنا سیکھیں گے۔ یہ پہلا پروگرام ہے جو ہر پروگرامر لکھتا ہے!

📝 اقدامات

پہلا قدم: VS Code کھولیں

  1. اپنے ڈیسک ٹاپ یا اسٹارٹ مینو پر VS Code آئیکن پر کلک کریں۔
  2. VS Code کے کھلنے کا انتظار کریں۔

دوسرا قدم: ایک نئی فائل بنائیں

  1. Explorer آئیکن پر کلک کریں (بائیں طرف پہلا آئیکن)۔
  2. "Open Folder" پر کلک کریں اور "MyPrograms" نام کا نیا فولڈر بنائیں۔
  3. New File بٹن پر کلک کریں (پلس کے نشان والا صفحہ آئیکن)۔
  4. فائل کا نام ٹائپ کریں: hello.cpp اور Enter دبائیں۔
VS Code New File شکل 1: VS Code میں نئی فائل بنانا

تیسرا قدم: کوڈ لکھیں

  1. نیچے دیے گئے کوڈ کو فائل میں کاپی اور پیسٹ کریں۔
// میرا پہلا C++ پروگرام #include <iostream> using namespace std; int main() { cout << "Hello World!" << endl; cout << "Welcome to C++ Programming" << endl; return 0; }
C++ Code in VS Code شکل 2: VS Code میں کوڈ لکھنا

چوتھا قدم: فائل محفوظ کریں

  1. فائل کو محفوظ کرنے کے لیے Ctrl + S (ونڈوز) یا Cmd + S (میک) دبائیں۔
  2. آپ کو Explorer میں فائل کا نام hello.cpp نظر آئے گا۔

پانچواں قدم: پروگرام چلائیں

  1. اوپر Run مینو پر کلک کریں۔
  2. "Run Without Debugging" پر کلک کریں (یا Ctrl + F5 دبائیں)۔
  3. اگر کمپائلر منتخب کرنے کو کہا جائے تو g++ یا gcc منتخب کریں۔
  4. آپ کا پروگرام چلے گا اور آؤٹ پٹ ٹرمینل میں دکھائے گا۔
VS Code Output شکل 3: VS Code ٹرمینل میں پروگرام کا آؤٹ پٹ

📊 مشاہدات

  • ایک نئی فائل hello.cpp بنائی گئی۔
  • کوڈ صحیح طریقے سے لکھا گیا۔
  • پروگرام کامیابی سے کمپائل اور چل گیا۔
  • آؤٹ پٹ میں "Hello World!" اور "Welcome to C++ Programming" دکھایا گیا۔

✅ نتیجہ

آپ کا پہلا C++ پروگرام کامیابی سے لکھا، محفوظ اور چلایا گیا۔ آپ نے VS Code میں ایک سادہ پروگرام بنانا اور چلانا سیکھ لیا ہے۔

💡 مشورہ: پروگرام چلانے سے پہلے ہمیشہ فائل محفوظ کریں۔ ایکسٹینشن .cpp C++ فائلوں کے لیے ہے۔ C فائلوں کے لیے .c استعمال کریں۔
📌 اہم: یقینی بنائیں کہ آپ نے VS Code میں C/C++ ایکسٹینشن انسٹال کی ہے۔ آپ اسے Extensions ٹیب (بائیں طرف مربع آئیکن) سے انسٹال کر سکتے ہیں۔
⬅ Back to Practical Notebooks