How to find out the type of variable C++

To determine the type of variable in C++ there is a function typeid().name() library typeinfo which must be pre-connected with

#include <typeinfo>

typeid().name()

Small demonstration

#include <string> #include <iostream> #include <typeinfo> int main() { // Create four variables of different types int int_var = 1; float float_var = 1.0; char char_var = '0'; std::string str1 = "www.heihei.ru"; // We will display the result of the typeid std::cout << typeid(int_var).name() << std::endl; std::cout << typeid(float_var).name() << std::endl; std::cout << typeid(char_var).name() << std::endl; std::cout << typeid(str1).name() << std::endl; return 0; }

The result

int float char class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > C:\Users\ao\source\repos\typeid\x64\Debug\typeid.exe (process 132920) exited with code 0. Press any key to close this window . . .

All four types are defined.

In other languages

Статьи о C++
Вектор. Часть 0.
Вектор. Часть 1.
Вектор. Часть 2.
Указатели
Классы
SFML
Тетрис на C++ с библиотекой SFML2
SDL
Массив Структур
Решение задач на C++
Как создать пустую строку в C++
Errors C++

Article author: Andrei Olegovich

Похожие статьи
Development in C++
Function overloading
Splitting code into parts
Vector
Pointers
Classes
SFML
Tetris in C++ with the SFML2 library
SDL
Array of structures
How to find out the type of a variable in C++
Problem solving in C++
How to create an empty line in C++
Errors C++

Search this site

Channel @aofeed Chat @aofeedchat

Contacts and cooperation:
I recommend our hosting beget.com
Write to info@aredel.com if you:
1. Want to write an article for our site or translate an article into your native language.
2. Want to place thematically relevant ads on the site.
3. Ads on my site pass maximum censorship. If you see an ad block unsuitable for school-age children, shocking or misleading - please contact us by e-mail
4. Found a mistake, inaccuracy, bug, etc. on the site. ... .......
5. Articles can be shared on social media by clicking a network icon: