C ++ type conversion

Where can I find an overview of type conversion, for example. string to integer, etc.?

Because of the comments, so far I’ll clarify: I am looking for a list / table that says: To convert a string to int, use: ... And the same for other data types (where possible): double to int, char to a string ...

+4
source share
4 answers

If it is a string to / from other types, then stringstream or increase :: lexical_cast .

For other types, it will depend on the types, but maybe look at the standard casting patterns? static_cast and dynamic_cast should do most of what you need, or there are const_cast and reinterpret_cast, which, as a rule, are only useful for working with older systems.

+11
source

Threads are essentially C ++ string conversion operators.

You also have an available C conversion method from sprintf, but it is massively error-prone and insecure.

+1
source

The standard library has functions for converting strings ↔ int. You should take any C ++ reference or search Google.

I am more familiar with C, but I believe that the C ++ functions are the same: atoi, strtoi, etc.

0
source

I would recommend reading a link about a string class , and then something about for different data types in general .

-1
source

Source: https://habr.com/ru/post/1302744/


All Articles