public member function
<typeinfo>

std::type_info::name

const char* name() const;
const char* name() const noexcept;
Get type name
Returns a null-terminated character sequence that may identify the type.

The particular representation pointed by the returned value is implementation-defined, and may or may not be different for different types.

Parameters

none

Return Value

A pointer to a c-string with the name for the object.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
// type_info::name example
#include <iostream>       // std::cout
#include <typeinfo>       // operator typeid

int main() {
  int i;
  int * pi;
  std::cout << "int is: " << typeid(int).name() << '\n';
  std::cout << "  i is: " << typeid(i).name() << '\n';
  std::cout << " pi is: " << typeid(pi).name() << '\n';
  std::cout << "*pi is: " << typeid(*pi).name() << '\n';

  return 0;
}


Possible output:
int is: int
  i is: int
 pi is: int *
*pi is: int

Exception safety

No-throw guarantee: this member function never throws exceptions.

See also