EZ Notes Logo

EZNotes

🎯 Aim

To learn how to write, edit, and save a C/C++ program correctly in Visual Studio Code.

🛠️ What You Need

  • Visual Studio Code installed on your computer
  • C/C++ extension installed in VS Code
  • A folder to save your programs

📖 Introduction

In the previous practicals, you learned how to install VS Code and write your first program. In this practical, you will learn the proper way to write, edit, and save a C/C++ program. You will also learn about the file extension .cpp and how to organize your programs.

📝 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 Folder

  1. Click the Explorer icon (📁) on the left side.
  2. Click "Open Folder".
  3. Choose a location on your computer (like Desktop or Documents).
  4. Click "New Folder" and name it "CPP Programs".
  5. Click "Select Folder" to open it.
Creating a New Folder in VS Code Figure 1: Creating a New Folder in VS Code

Step 3: Create a New File

  1. Click the New File button (📄+) next to your folder name.
  2. Type the file name: firstprogram.cpp and press Enter.
  3. Your new file will open in the editor.
Creating a C++ File in VS Code Figure 2: Creating a C++ File in VS Code

Step 4: Write Your Program

  1. Copy and paste the code below into your file.
// My Second C++ Program #include <iostream> using namespace std; int main() { // This is a comment cout << "This is my second C++ program." << endl; cout << "I am learning C++ programming." << endl; cout << "I can write and save programs now." << endl; return 0; }
C++ Code in VS Code Editor Figure 3: Writing C++ Code in VS Code Editor

Step 5: Save Your Program

  1. Press Ctrl + S (Windows) or Cmd + S (Mac) to save.
  2. You will see a white dot next to the file name disappear — this means it is saved.
  3. Check the file name in the Explorer — it should show firstprogram.cpp.
File Saved in VS Code Figure 4: File Successfully Saved

Step 6: Edit and Update Your Program

  1. Change the text in the cout statements to something else.
  2. For example, write your name instead of "I am learning C++ programming."
  3. Press Ctrl + S again to save your changes.

📊 Observations

  • A new folder CPP Programs was created.
  • A new file firstprogram.cpp was created.
  • The file was saved with the correct extension .cpp.
  • The code was written correctly with comments.
  • The file can be edited and saved again.
  • The saved file appears in the Explorer.

✅ Result

You have successfully written, edited, and saved a C++ program in VS Code. You now know how to create folders, create files, write code, and save your work properly.

💡 Tip: Always use the .cpp extension for C++ files. This helps VS Code know which language you are using and provides features like syntax highlighting.
📌 Important: Save your file frequently! Press Ctrl + S after every change to avoid losing your work.

🎯 مقصد

Visual Studio Code میں C/C++ پروگرام کو صحیح طریقے سے لکھنا، اس میں ترمیم کرنا اور محفوظ کرنا سیکھنا۔

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

  • آپ کے کمپیوٹر پر Visual Studio Code انسٹال ہو
  • VS Code میں C/C++ ایکسٹینشن انسٹال ہو
  • اپنے پروگرام محفوظ کرنے کے لیے ایک فولڈر

📖 تعارف

پچھلی عملیات میں، آپ نے VS Code انسٹال کرنا اور اپنا پہلا پروگرام لکھنا سیکھا۔ اس عملی میں، آپ C/C++ پروگرام کو صحیح طریقے سے لکھنے، اس میں ترمیم کرنے اور محفوظ کرنے کا طریقہ سیکھیں گے۔ آپ فائل ایکسٹینشن .cpp اور اپنے پروگراموں کو منظم کرنے کے بارے میں بھی جانیں گے۔

📝 اقدامات

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

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

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

  1. بائیں طرف Explorer آئیکن (📁) پر کلک کریں۔
  2. "Open Folder" پر کلک کریں۔
  3. اپنے کمپیوٹر پر کوئی جگہ منتخب کریں (جیسے ڈیسک ٹاپ یا ڈاکیومنٹس)۔
  4. "New Folder" پر کلک کریں اور اس کا نام "CPP Programs" رکھیں۔
  5. اسے کھولنے کے لیے "Select Folder" پر کلک کریں۔
Creating a New Folder in VS Code شکل 1: VS Code میں نیا فولڈر بنانا

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

  1. اپنے فولڈر کے نام کے ساتھ New File بٹن (📄+) پر کلک کریں۔
  2. فائل کا نام ٹائپ کریں: firstprogram.cpp اور Enter دبائیں۔
  3. آپ کی نئی فائل ایڈیٹر میں کھل جائے گی۔
Creating a C++ File in VS Code شکل 2: VS Code میں C++ فائل بنانا

چوتھا قدم: اپنا پروگرام لکھیں

  1. نیچے دیے گئے کوڈ کو اپنی فائل میں کاپی اور پیسٹ کریں۔
// میرا دوسرا C++ پروگرام #include <iostream> using namespace std; int main() { // یہ ایک تبصرہ ہے cout << "This is my second C++ program." << endl; cout << "I am learning C++ programming." << endl; cout << "I can write and save programs now." << endl; return 0; }
C++ Code in VS Code Editor شکل 3: VS Code ایڈیٹر میں C++ کوڈ لکھنا

پانچواں قدم: اپنا پروگرام محفوظ کریں

  1. محفوظ کرنے کے لیے Ctrl + S (ونڈوز) یا Cmd + S (میک) دبائیں۔
  2. آپ فائل کے نام کے ساتھ ایک سفید نقطہ غائب ہوتے دیکھیں گے — اس کا مطلب ہے کہ یہ محفوظ ہو گئی ہے۔
  3. Explorer میں فائل کا نام چیک کریں — اسے firstprogram.cpp دکھانا چاہیے۔
File Saved in VS Code شکل 4: فائل کامیابی سے محفوظ

چھٹا قدم: اپنے پروگرام میں ترمیم کریں

  1. cout والی لائنوں میں متن کو کسی اور چیز میں تبدیل کریں۔
  2. مثال کے طور پر، "I am learning C++ programming." کی بجائے اپنا نام لکھیں۔
  3. اپنی تبدیلیاں محفوظ کرنے کے لیے دوبارہ Ctrl + S دبائیں۔

📊 مشاہدات

  • ایک نیا فولڈر CPP Programs بنایا گیا۔
  • ایک نئی فائل firstprogram.cpp بنائی گئی۔
  • فائل کو صحیح ایکسٹینشن .cpp کے ساتھ محفوظ کیا گیا۔
  • کوڈ کو تبصروں کے ساتھ صحیح طریقے سے لکھا گیا۔
  • فائل میں ترمیم اور دوبارہ محفوظ کیا جا سکتا ہے۔
  • محفوظ کردہ فائل Explorer میں ظاہر ہوتی ہے۔

✅ نتیجہ

آپ نے VS Code میں C++ پروگرام کو کامیابی سے لکھا، اس میں ترمیم کی اور محفوظ کیا۔ اب آپ جانتے ہیں کہ فولڈرز کیسے بناتے ہیں، فائلیں کیسے بناتے ہیں، کوڈ کیسے لکھتے ہیں، اور اپنے کام کو صحیح طریقے سے محفوظ کرتے ہیں۔

💡 مشورہ: C++ فائلوں کے لیے ہمیشہ .cpp ایکسٹینشن استعمال کریں۔ اس سے VS Code کو معلوم ہوتا ہے کہ آپ کون سی زبان استعمال کر رہے ہیں اور نحو کی ہائی لائٹنگ جیسی خصوصیات فراہم کرتا ہے۔
📌 اہم: اپنی فائل کو بار بار محفوظ کریں! اپنا کام کھونے سے بچنے کے لیے ہر تبدیلی کے بعد Ctrl + S دبائیں۔
⬅ Back to Practical Notebooks