How to convert an integer to a string portably?

后端 未结 2 1839
暖寄归人
暖寄归人 2021-01-18 06:30

I was looking for a way to convert an integer to a string in a portable manner (portable among at least Windows & Linux and x86 and x86_64) and I though itoa(X)

相关标签:
2条回答
  • 2021-01-18 07:20

    If you aren't doing this terribly often, how about a runtime library routine that writes a few numbers to memory, analyzes the results and stores an encoding type? From then on you just switch on your "encoding type" to select which conversion routine to use.

    0 讨论(0)
  • 2021-01-18 07:25

    Most often you just use printf("%d");

    http://en.wikipedia.org/wiki/Printf

    You can use sprintf if you need it in a buffer, but how often do you convert to a string and not write it to a file or output device?

    0 讨论(0)
提交回复
热议问题