It is common to convert string to int and int to string in C++ programs. This post introduces how to convert a valid string to int and int to string in C++ using C and C++ ways and libraries. If your string is not a valid integer string, you should check it first or use other methods.
在C ++程序中,通常将字符串转换为int并将int转换为字符串。 这篇文章介绍了如何使用C和C ++方式和库在C ++中将有效字符串转换为int以及将int转换为字符串。 如果您的字符串不是有效的整数字符串,则应首先检查它或使用其他方法。
将字符串转换为int (Convert string to int)
1. C风格的方式 (1. The C-style way)
Use C standard library strtol
(avoid