N
N
Nikolay2014-11-16 15:00:56
Programming
Nikolay, 2014-11-16 15:00:56

What is the analogue of the php function is_string() in C++?

Actually, all the functions of checking the entered data into a variable are of interest - which library is responsible for this?
And, is there any function reference like on php.net?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
N
Nikita Gushchin, 2014-11-16
@iNikNik

The directory is - MSDN.
And you don't need to check whether a variable is a string in c++ - because each variable has its own data type and it is immediately clear whether the line in front of us (an object of the String class) or not. And given that a string is an array of characters, then any (roughly speaking) memory area can be represented as an array of char

S
Sergey, 2014-11-16
Protko @Fesor

Actually, all the functions of checking the entered data into a variable are of interest.

is_string in php checks that a variable is of that type. In C++, this makes no sense because, unlike PHP, in C++ the variable is declared with some type.
If you are interested in checks like is_numeric that check if the string contains a number or something else, then there is no such thing in std and you will either have to connect the library or implement it yourself (just run through the array of chars and return false if you encounter chars from the wrong range. Well, or regular expressions But again, few people are driven by this, since with user input it is possible to sort it all out and, again, there is no point in these checks.

I
Ilya Evseev, 2014-11-16
@IlyaEvseev

1) Function reference - www.cplusplus.com/reference
2) Crutches like is_string() only make sense in dynamically typed languages.
C++ is a statically typed language.
It uses the std::string class to store strings.

M
Mercury13, 2014-11-17
@Mercury13

C++ is a statically typed language, and if x is declared as string, then it is always string. And if as an int, then it is never a string. So the is_string function in C++ just doesn't make sense.
True, there are islands of dynamic typing like VARIANT from OLE - you already look at this in place ( msdn.microsoft.com/en-us/library/cc237865.aspx) and, most likely, this is not your question.
Yes, you wanted to validate input. For example, to check if a string is a number, you can use www.cplusplus.com/reference/cstdlib/strtod (don't forget to check endptr afterwards!)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question