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?

8th May 2021, 10:30 AM
Koloroj
5 odpowiedzi
+ 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
8th May 2021, 11:16 AM
XXX
XXX - avatar
+ 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?
8th May 2021, 10:39 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 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
8th May 2021, 11:07 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
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++?
8th May 2021, 10:49 AM
Koloroj
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.
8th May 2021, 11:09 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar