rumman_sust's blog

By rumman_sust, 3 years ago, In English,

If we want to know a variable's type id or compare two variables' type ids are same or not, here is a keyword "typeid" in C++.

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

int main()
{
    int intvar;
    long long longlongvar;
    bool boolvar;

    cout<<"Type name of int: "<<typeid(int).name()<<"\n";
    cout<<"Type name of intvar: "<<typeid(intvar).name()<<"\n\n";
    cout<<"Type name of long long: "<<typeid(long long).name()<<"\n";
    cout<<"Type name of longlongvar: "<<typeid(longlongvar).name()<<"\n\n";
    cout<<"Type name of bool: "<<typeid(bool).name()<<"\n";
    cout<<"Type name of boolvar: "<<typeid(boolvar).name()<<"\n\n";

    return 0;
}

This code shows:

Type name of int: i
Type name of intvar: i

Type name of long long: x
Type name of longlongvar: x

Type name of bool: b
Type name of boolvar: b

"i" for integer, "x" for long long and "b" for bool.

 
 
 
 
  • Vote: I like it  
  • +16
  • Vote: I do not like it  

»
3 years ago, # |
  Vote: I like it +16 Vote: I do not like it

Here are some more type names for other variables.

bool = b
char = c
unsigned char = h
short = s
unsigned short = t
int = i
unsigned int = j
long = l
unsigned long = m
long long = x
unsigned long long = y
float = f
double = d
long double = e
string = Ss
int[] = A_i
double[] = A_d
vector<int> = St6vectorIiSaIiEE
set<int> = St3setIiSt4lessIiESaIiEE
pair<int, int> = St4pairIiiE
map<int, int> = St3mapIiiSt4lessIiESaISt4pairIKiiEEE
stack<int> = St5stackIiSt5dequeIiSaIiEEE
queue<int> = St5queueIiSt5dequeIiSaIiEEE
deque<int> = St5dequeIiSaIiEE
priority_queue<int> = St14priority_queueIiSt6vectorIiSaIiEESt4lessIiEE
tuple<int, int, int, int> = St5tupleIIiiiiEE
map< pair<int, int>, vector< priority_queue<int> > > = St3mapISt4pairIiiESt6vectorISt14priority_queueIiS2_IiSaIiEESt4lessIiEESaIS8_EES6_IS1_ESaIS0_IKS1_SA_EEE

you can view the code file here : http://ideone.com/XWz3yR

»
3 years ago, # |
Rev. 2   Vote: I like it +1 Vote: I do not like it

Good new thing...but I have a question... is it helpful for problem solving specially CF round? Thanks in advance...