Supercharge your development with unmatched features:
Access a full terminal environment, run Linux commands, and manage your project’s dependencies directly within the IDE.
Browse and interact with websites directly within the IDE. Supports real-time interaction with web content without leaving the workspace.
Manage your project files and directories effortlessly within the IDE. Create, edit, rename, move, and delete files—all in one place.
Experience seamless code editing with real-time syntax highlighting, tab support, and intelligent code suggestions for a smoother development workflow.
C++ is a powerful general-purpose programming language that supports procedural, object-oriented, and generic programming. It is widely used for game development, system programming, and competitive programming.
g++ --version
in your terminal or command prompt.Let’s write our first C++ program:
#include <iostream>
int main() {
std::cout << "Hello, World!" << std::endl;
return 0;
}
Save this code as hello.cpp
and compile it using g++ hello.cpp -o hello
. Run the program by executing ./hello
.
C++ supports various data types and variables that need to be declared before use.
// Example:
int age = 25;
double pi = 3.14159;
char grade = 'A';
bool isStudent = true;
C++ uses if
, else if
, and else
for decision-making.
// Example:
int num = 10;
if (num > 0) {
std::cout << "Positive number" << std::endl;
} else if (num == 0) {
std::cout << "Zero" << std::endl;
} else {
std::cout << "Negative number" << std::endl;
}
// Example:
for (int i = 0; i < 5; i++) {
std::cout << i << std::endl;
}
// Example:
int count = 0;
while (count < 5) {
std::cout << count << std::endl;
count++;
}
#include <iostream>
void greet(const std::string& name) {
std::cout << "Hello, " << name << "!" << std::endl;
}
int main() {
greet("Alice");
return 0;
}
#include <iostream>
class Person {
public:
std::string name;
int age;
void introduce() {
std::cout << "Name: " << name << ", Age: " << age << std::endl;
}
};
int main() {
Person p;
p.name = "Alice";
p.age = 25;
p.introduce();
return 0;
}
#include <iostream>
int main() {
int num = 10;
int* ptr = #
std::cout << "Value: " << *ptr << ", Address: " << ptr << std::endl;
int& ref = num;
std::cout << "Reference Value: " << ref << std::endl;
return 0;
}
// Writing to a file:
#include <iostream>
#include <fstream>
int main() {
std::ofstream file("example.txt");
if (file.is_open()) {
file << "Hello, C++!" << std::endl;
file.close();
}
return 0;
}
// Reading from a file:
#include <iostream>
#include <fstream>
#include <string>
int main() {
std::ifstream file("example.txt");
std::string line;
if (file.is_open()) {
while (getline(file, line)) {
std::cout << line << std::endl;
}
file.close();
}
return 0;
}
#include <iostream>
#include <vector>
int main() {
std::vector<int> nums = {1, 2, 3, 4, 5};
for (int num : nums) {
std::cout << num << std::endl;
}
return 0;
}
C++ builds on the C standard libraries and provides additional libraries for advanced functionality, such as:
iostream
: For input and output operations, such as cin
and cout
.string
: For manipulating and managing strings.vector
, map
, set
: For efficient data structures.algorithm
: For common algorithms like sort
, reverse
, and unique
.thread
: For multithreading capabilities.