Values output for Win32

I have a Win32 program with GUI and in that GUI there is an "EDIT" window for the output.

I need a lot of formatting and currently I use a code that goes like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

// global variables

char hlp[10000];
std::string str;

...

// somewhere inside a function

sprintf_s(hlp, "%.8f %d %02X ...", f, i, c, ...);
str += hlp;

...

sprintf_s(hlp, "%.8f %d %02X ...", f, i, c, ...);
str += hlp;

...

sprintf_s(hlp, "%.8f %d %02X ...", f, i, c, ...);
str += hlp;

// at the end of the function

SetWindowText(hOut, str.c_str());
SendMessage(hOut, EM_SCROLL, SB_BOTTOM, 0);


Is there a better way to do this using streams and << operations?
Last edited on
The question is, how would I rewrite the code above using std::stringstream ?
closed account (E0p9LyTq)
http://stackoverflow.com/questions/2342162/stdstring-formatting-like-sprintf

There is no easy way to format a C++ string without using 3rd party libraries or writing custom code, it would require using a lot of format specifiers.

String and I/O Formatting (Modern C ++) - msdn.microsoft.com
https://msdn.microsoft.com/en-us/library/hh438469.aspx

The Boost libraries have a Format library that provide printf-like formatting for C++:
http://www.boost.org/doc/libs/1_61_0/libs/format/doc/format.html
I see, thanks, in that case it seems there is no reason for me to use streams, I thought it might make things easier.
closed account (E0p9LyTq)
The Win32 API uses C-style strings, so sprintf() works.

The C library string functions have security risks, so Microsoft created string safe (StrSafe.h) functions:
https://msdn.microsoft.com/en-us/library/windows/desktop/ms647465(v=vs.85).aspx#_win32_Comparison_with_C_Run_time_String_Functions
Topic archived. No new replies allowed.