Essential C++

Input/Output:

cout<<"hello there!";
int x;
cin>>x;
int y=10;
long int z=1000000000;
double m=3.1416;
printf("%d %ld %lf",y,z,m);

Initialization:

set<int> st;
vector<int> v1={st.begin(),st.end()};
int arr[]={1,2,3,4};
int arr[10];
int arr[2][2];
vector<int> v2(10);
//TODO: 2d vector

Array:

array<int,6> arr;
arr.fill(0);

Vector:

vector<int> v1;
v1.push_back(10);
v1.pop_back();

Bit Manipulation:

int x  = y^z;
int numberOfOneBits = __builtin_popcount(x);

Type conversion:

string str= to_string(5);
int x= stoi("12312");
int y = 10;
long long z = (long long)y;
double  a = 5.12;
int b=static_cast<int>(a);
char ch = tolower('A');
bool chk= isDigit('1');

Iterator:

map<int,int> mp1;
map<int,int>::iterator it;
it=mp1.begin();
while(it!=mp1.end()){
	int key=*it->first;
	int val=*it->second;
	cout<<key<<" "<<val<<endl;
	it++;
}

For loop:

for(int i=0;i<x;i++)
	if(i%2==0)
		cout<<"even"<<endl;
	else
		continue;
vector<int> v1;
for(int x: v1){
	cout<<x<<" ";
}
map<int,int> mp;
for(auto x: mp){
	int key=x.first;
	int val=x.second;
	cout<<key<<" "<<val<<endl;
}
string str="Hello world";
for(char& ch:str){
	ch=tolower(ch);
}

Algorithm:

sort(v1.begin(),v1.end());
int x,int y;
swap(x,y);
int hi=max(x,y);
int lo=max)x,y);
reverse(v1.rbegin(),v1.rend());
int mn = *min_element(nums.begin(),nums.end());
int mx = *max_element(nums.begin(),nums.end());
int mn2 = min_element(arr,arr+9);
sort(arr.begin(),arr.end(),[](const int& a,const int& b){
	int x = __builtin_popcount(a);
	int y = __builtin_popcount(b);
	if(x==y) return a<b;
	else return x<y;
});

Math:

double x=sqrt(10);
double y = 5.0/2.0;
int z = abs(-10);
double m = abs(y);
double p = pow(2.0,4.0);
int k=pow(2,4);

String:

str.insert(str.begin()+5,"hello world");
str.erase(str.begin()+4,1);
str.substr(3,2);
int sz=s.size();

Map:

map<char,int> mp1;
if(mp1.count('a')==0)
	cout<<"Not found";
map<int,vector<int,int>> mp2;
mp1['c']++;
mp1.empty();
mp1.insert(pair<char,int>('a',10));

Set:

set<int> st;
st.insert(1);
st.insert(2);
int found = st.count(10);
st.erase(2);

List:

//TODO

Stack:

stack<int> st;
st.push(10);
int x=st.top();
st.pop();
bool status = st.empty();

Queue:

queue<int> qu;
qu.push(10);
int x=qu.front();
int y=qu.back();
qu.pop();
bool status = qu.empty();

Priority Queue

// TODO

Function:

int justDoIt(int x){
	x=x*10;
	reuturn x;
}
void anotherFunc(int x){
	cout<<x<<endl;
}
void print(int[] arr,int sz){
	cout<<arr[sz-1];
}
void twoDim(int[10][] arr,int y){
	for(int i=0;i<10;i++)
		for(int j=0;j<y;j++)
			cout<<arr[i][j]<<" ";
}
Comments (2)