Is there any built in functions in c++ win 32 for number system conversions?

StackOverflow https://stackoverflow.com/questions/22140158

  •  19-10-2022
  •  | 
  •  

문제

I am doing calculator application.

For the Decimal, Binary, Octal and Hexadecimal numbers. For that I need to convert numbers from one to another number system. So can any one tell me about any built in functions for conversions, eg. Dec to Binary, in c++.

If there is no built in functions, can anyone suggest me a standard code to convert between Dec to Binary, Dec to Octal ,Dec to Hex and Vice a versa.

Thanks in advance.

올바른 솔루션이 없습니다

다른 팁

wsprintf can do some limited numeric conversions, but I'd generally advise against using it.

Although they're in the standard library instead of the Win32 API per se, I'd use std::to_string if your compiler/library are new enough to include it, and strtol otherwise.

For converting a number to a string, you can use a stringstream for hex, octal or decimal. For binary, you generally want to create a std::bitset from the number first, then write that to the stream.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top