Learn how to compile and run your C/C++ programs using Visual Studio Code.
To learn how to compile and run a C/C++ program using Visual Studio Code.
Compiling is the process of converting your source code (the code you write) into a program that the computer can run. When you compile a C/C++ program, the compiler checks your code for errors and creates an executable file. In this practical, you will learn how to compile and run your C++ programs using VS Code.
Figure 1: Opening a C++ File in VS Code
Explanation:
g++ — the C++ compiler
firstprogram.cpp — your source code file
-o firstprogram — the output executable file name
Figure 2: Compiling the C++ Program
Note: On Windows, you would type:
Figure 3: Running the Compiled Program
cout line).g++ command.You have successfully compiled and run a C++ program in VS Code. You now know how to use the terminal to compile and execute your programs. This is an important skill for every programmer.
Visual Studio Code کا استعمال کرتے ہوئے C/C++ پروگرام کو کمپائل اور رن کرنا سیکھنا۔
کمپائل کرنا وہ عمل ہے جس میں آپ اپنے سورس کوڈ (جو آپ لکھتے ہیں) کو ایک پروگرام میں تبدیل کرتے ہیں جسے کمپیوٹر چلا سکتا ہے۔ جب آپ C/C++ پروگرام کمپائل کرتے ہیں، تو کمپائلر آپ کے کوڈ میں غلطیاں چیک کرتا ہے اور ایک ایگزیکیوٹیبل فائل بناتا ہے۔ اس عملی میں، آپ VS Code کا استعمال کرتے ہوئے اپنے C++ پروگراموں کو کمپائل اور رن کرنا سیکھیں گے۔
شکل 1: VS Code میں C++ فائل کھولنا
وضاحت:
g++ — C++ کمپائلر
firstprogram.cpp — آپ کی سورس کوڈ فائل
-o firstprogram — آؤٹ پٹ ایگزیکیوٹیبل فائل کا نام
شکل 2: C++ پروگرام کمپائل کرنا
نوٹ: ونڈوز پر، آپ ٹائپ کریں گے:
شکل 3: کمپائل شدہ پروگرام چلانا
cout لائن شامل کریں)۔g++ کمانڈ کا استعمال کرتے ہوئے کمپائل کیا گیا۔آپ نے VS Code میں C++ پروگرام کو کامیابی سے کمپائل اور چلایا ہے۔ اب آپ جانتے ہیں کہ ٹرمینل کا استعمال کرتے ہوئے اپنے پروگراموں کو کیسے کمپائل اور چلانا ہے۔ یہ ہر پروگرامر کے لیے ایک اہم مہارت ہے۔