#include <iostream>
using namespace std;
int main() {
cout << "Hello, World!";
return 0;
}
#include
: Includes header files like <iostream>, <string>, <cmath>,
<fstream>#define
: Defines constants/macrosint age;
char grade = 'A';
cout << "Age: " << age;
cin >> age;
getline(cin, var);
+ - * / %
== != > < >= <=
&& || !
& | ^ ~ << >>
int a = 5; float b = a;
int a = (int)5.5;
if, else if, else
switch-case-break
break, continue
for, while, do-while
int add(int, int);
sum = add(5, 3);
int var = 12;
int& ref = var; //Reference
&
operator#include <vector>
vector<datatype> vector_name;
push_back(), pop_back(),
at(i), size(), clear()
Automatically resizes when modified
int x = 10;
int *ptr = &x;
*ptr = 20;
int a[3] = {10, 20, 30};
int b[2][3] = {
{1, 2, 3},
{4, 5, 6}
};
string name[] = "Imad";
length(), append(), substr().
getline(cin, str)
- Reads full line (including spaces)cin >> str
- Reads up to spaces.append("...")
- Concatenates.find("...")
- Searchstruct Student {
int id;
string name;
};
struct Student s1;
s1.id = 101;
union Data {
int i;
char str[20];
};
typedef struct {
int id;
char name[20];
} Student;
Student s1;
enum Day {SUN, MON};
enum Day d = MON;
class MyClass {
public:
void display() {
cout << "Hello";
}
};
MyClass obj;
obj.display();
#include <fstream>
int main() {
// Create and open file
ofstream MyFile("f.txt");
// Write to the file
MyFile <<"Hello! world";
// Close the file
MyFile.close();
}
#include <fstream>
ofstream outFile("f.txt");
file << data
- Write datafile >> var
- Read datagetline(file, str)
- Read linefile.close()
- Close filefile.is_open()
- Check statusfstream file;
file.open("f.txt",ios::out);
ios::in
- Read modeios::out
- Write modeios::app
- Append modeios::ate
- Start at endios::binary
- Binary modetry{
//code to try
throw exception;
}
catch(){
//code to handle errors
}
return_type func(params) {
if (base_case)
return value;
else
return func(new_params);
}