how to using std::format for numerics?

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

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.
3,527 questions
0 comments No comments
{count} votes

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

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

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful