Implicit type promotion rules

C was designed to implicitly and silently change the integer types of the operands used in expressions. There exist several cases where the language forces the compiler to either change the operands to a larger type, or to change their signedness. The rationale behind this is to prevent accidental overflows during arithmetic, but also to … Read more

Easiest way to convert int to string in C++

C++11 introduces std::stoi (and variants for each numeric type) and std::to_string, the counterparts of the C atoi and itoa but expressed in term of std::string. #include <string> std::string s = std::to_string(42); is therefore the shortest way I can think of. You can even omit naming the type, using the auto keyword: auto s = std::to_string(42); … Read more

Problems converting float to int in C++

You never initialize memory for the vector. You’ll have to do float *vector = new float[vectorSize]; and only then fill it with values (and then delete[] vector;) Also, why are you using an array of floats while there’s std::vector that is a better choice in your situation. What’s more, avoid calling your array vector since … Read more

Converting String^ to Int

Standard ‘learning the language’ warning: This isn’t C++ you’re writing, it’s C++/CLI. C++/CLI is a language from Microsoft intended to allow C# or other .Net languages to interface with unmanaged C++. In that scenario, C++/CLI can provide the translation between the two. If you’re still learning C++, please do not start with C++/CLI. In order … Read more

Convert string[] to Array

A string[] is already an Array (because each concrete array type derived from Array) – and Split already gives a string[], so you don’t need to call ToArray on the result. So this: data = (Array) ids.Split(‘,’).ToArray(); can just be: data = ids.Split(‘,’); The result is an array, so there’s no other work to do. … Read more