how to using std::format for numerics?

asked 2021-11-08T03:39:40.813+00:00
DangDKhanh-2637 706 Reputation points

Hi,
I'm translating code from .NET.
Can I format wstring for multiple parameters at once?
I am trying to format rgb color base long color:

const wstring s = std::format(to_wstring(colorVal % 256), L"00") + L", " +
std::format(to_wstring((colorVal / 256) % 256), L"00") + L", " +
std::format(to_wstring(colorVal / 65536), L"00");

However the code seems to be quite slow, can you point me to a better approach?

Thank you!

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
2,617 questions
No comments
{count} votes

Accepted answer
  1. answered 2021-11-08T03:58:27.91+00:00
    Igor Tandetnik 1,096 Reputation points

    You are probably looking for something like std::format(L"{}, {}, {}", colorVal % 256, (colorVal / 256) % 256, colorVal / 65536)


0 additional answers

Sort by: Most helpful