简体   繁体   中英

C++ type conversion

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

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

If it's string to/from other types then stringstream or boost::lexical_cast .

For other types it will depend on the types, but maybe look up the standard cast templates? static_cast and dynamic_cast should do most things you need, or there is const_cast and reinterpret_cast which tend to only be useful for dealing with legacy systems.

Streams are essentially C++'s string conversion operators.

You also have available C's conversion method of sprintf, but that is massively error-prone and unsafe.

There are functions in the standard library to do string<->int conversions. You should grab any reference book on C++, or search Google.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM