সোমবার, ২৫ জুলাই, ২০১৬

সি-প্লাস-প্লাস নোট

// 
string st;
cin >> st; // Input "Apu"

cout << st.at(1) << endl; //output "p"

//includes all c , cpp libraries
#include <bits/stdc++.h>


// getting a line of string cpp
string st;

getline(cin , st);//input "I love cpp"

cout << st << endl; //output "I love cpp"


//if a char in string is letters

string st;
cin >> st;

if(isalpha(st.at(0)))
    cout << "Letters" << endl;

//initializing array with a value

int row[8];

memset(row, 0 , sizeof(row));//it initializes row array with 0 value



memset(array, 0, sizeof(array[0][0]) * m * n); where m and n is height and width

//getting max value of an array

int ara[5] = {9, 1 , 2, 3, 5};
int max = *max_element(ara, ara+5);// max = 9

//using pair in vector

vector<pair<int , bool > > v;

v.push_back(make_pair(3, 5));

for(vector<pair<int, bool> >::iterator it = v.begin() ; it != v.end() ; it++)
{
     cout << it->first << endl;//output 3
     cout << it->second << endl;output 5
}


//how to know how many values in an array is less than or equal a value

    int a[5] = {1, 3, 7 , 8 , 9};
    cout << upper_bound(a, a+5, 8)-a << endl;//output 4 cause there are 4 values <= 8 in the array
    cout << lower_bound(a, a+5, 9)-a << endl;//output 4 cause there are 4 values < 9 in the array


//how to take input line of integers in an array where number of integers is unknown

string st;
int ara[100], n;

getline(cin , st); //12 23 5 6 8
n = 0;
istringstream is(st);
while(cin>>ara[n])n++;
for(int i = 0; ara[i] ; i++)
{
        cout << ara[i] << " "; // 12 23 5 6 8
          }


//for iterating Through A map and nesting vector or map


std::map<std::string, std::map<std::string, std::string>> mymap;

for(auto const &ent1 : mymap) {
  // ent1.first is the first key
  for(auto const &ent2 : ent1.second) {
    // ent2.first is the second key
    // ent2.second is the data
  }
}

//for knowing number of 1 bits in a integer




int num_of_bits = __builtin_popcount(2)//2 = 00000010
cout << num_of_bits << endl; // output is one



How it feels like reading a book in a kindle reader?

Recently I have a amazon kindle reader as gift from my little brother. Though I am in temptation to have one for 3 years. One of my friend ...