Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

how to use #define c++

// If there is a command or anything that is too large to type, you use it often
// and wish you could type it faster, you can use #define to define it as
// something else,

#include <bits/stdc++.h>
using namespace std; 

// for example one you can define 'push_back' command for vectors as 'pb'
#define pb push_back
// You can actually give it some values too, like this
#define fo(i,a,b) for(int i = a; i < b; i++)

int main(){
  vector<int> vec;
  // Now do this
  vec.pb(5);
  fo(i,0,10){
    cout << i << endl;
  }
  // Instead of this
  vec.push_back(5);
  for(int i = 0; i < 10; i++){
    cout << i << endl;
  }
}
 
PREVIOUS NEXT
Tagged:
ADD COMMENT
Topic
Name
9+8 =