Example Analysis of string, Integer and floating Point conversion in C++
This article mainly introduces the C++ string and integer and floating-point conversion example analysis, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article. Next, let the editor take you to know about it.
1. String and char [] 1. String to char []
String is a class, while the variable name of char [] is essentially an address, which at first glance doesn't seem easy to convert.
But in fact, we can migrate the values in string to char [] as a whole by address:
# include # include using namespace std;int main () {string s = "123.123"; char a [101l]; strcpy (a, s.c_str ()); / / strcpy (a, s.data ()); / / equivalent to the above statement, you can cout either of them