C ++类型转换(C++ type conversion)

我在哪里可以找到类型转换的概述,例如字符串到整数等?

由于到目前为止的意见,我会澄清:我正在寻找一个列表/表,说:要将字符串转换为一个int,使用:...和其他数据类型相同(在可能的情况下):double to int,char到字符串,...

Where can I find an overview of type conversion, e.g. 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, ...

最满意答案

如果它的字符串来自/来自其他类型,则stringstream或boost :: lexical_cast 。

对于其他类型,它将取决于类型,但也许查找标准的演员模板? static_cast和dynamic_cast应该完成你需要的大部分事情,或者const_cast和reinterpret_cast往往只对处理遗留系统有用。

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.

更多推荐