0
Can data types get converted to one another in Go? What about in C++? How?
I'm wondering if, in Go and C++, strings can get converted to integers, ints to strings, etcetera. If they do, how?
5 ответов
+ 3
Koloroj
In C++, a string can be converted to integer using the std::stoi() function of the <string> header.
https://en.cppreference.com/w/cpp/string/basic_string/stol
The opposite can be done using the std::to_string() function of the <string> header
https://en.cppreference.com/w/cpp/string/basic_string/to_string
In Go, string can be converted to integer using the ParseInt() function of the strconv package.
https://golang.org/pkg/strconv/#ParseInt
Using the Itoa() function of the same package, you can convert integer to string
https://golang.org/pkg/strconv/#Itoa
+ 1
Hi! yes, in some cases they can, depending on the language(there are languages with strict and non-strict typing), they can explicitly or implicitly pass into each other. what language do you mean?
+ 1
In C++, there is a distinction between explicit and implicit conversion of data types. Implicit data type conversion is performed by the C++ compiler, but explicit data conversion is performed by the programmer himself. The result of any calculation will be converted to the most accurate data type, from the data types that are involved in the calculation.
Examples:
int / int = int
int / float = float
float /int = float
Manual change:
x = 15 / 7 // int
x = 15.0 /7 // float
0
Yaroslav Vernigora Whoops, sorry, I forgot to specify the language. (I did put the language in tge tags, though.)
Nevertheless, do you know if they can in C++?
0
in С++, the "auto" keyword allows you to automatically determine the type of a declared variable. It determines the data type of a variable by its value.