Home > Software engineering >  Cstrings Format problem
Cstrings Format problem

Time:09-15

Everybody is good, I want to ask a simple question, is to use Fomrat cstrings, want the sequence parameter change, such as
SzText. The Format (" this is % d % d ", 12, 13);
Into the final result of this is 13 12 rather than this is 12 13
According to some online
This Format (" this is % 1: % d 0: d ", 12, 13);
But always error

-> Here are online instructions:

 
Type done, below is the instruction format Type:
":" [index] this how to express it, look at an example

Format (" this is % d % d ", 12, 13);
One of the first % d index is 0, the second % d is 1, so characters display
So this is 12 13

If you define like this:

Format (" this is % 1: % d 0: d ", 12, 13);
Then the returned string becomes a

This is 13 12

https://www.xuebuyuan.com/1609332.html

To cstrings calls the method is as follows

Cstrings szText;
SzText. The Format (" this is % 1: % d 0: d ", 12, 13);
AfxMessageBox (szText);

But always an error, it is what reason, thank you!

CodePudding user response:

It is to use FormatMessage ()

 cstrings strText (TEXT (" ")); 
StrText. FormatMessage (TEXT (" this is % 2! d! The % 1! D!" ), 12, 13);
AfxMessageBox (strText);


https://docs.microsoft.com/en-us/cpp/atl-mfc-shared/reference/cstringt-class? View=v - 2019 # format

CodePudding user response:

The
% n! The format string! Identifies an insert. The value of n can be in The range from 1 through 99. The format string (which must be surrounded by The exclamation marks) is optional and defaults to! s! If not specified. For more information, see the Format Specification Fields.

CodePudding user response:

Thank you for your reply, I just tried it on and use FormatMessage can solve, but floating point don't know how to format?

Cstrings strText (TEXT (" "));
StrText. FormatMessage (" this is % 2! d! The % 1! d! % 3% ", 12, 13, "I am a test text", 5.25);
//strText at this time is equal to "this is 13 12 I am f test text", rather than what I want, "this is 13 12 I am test text 5.25"

CodePudding user response:

! d! Is an integer try! f!

CodePudding user response:


Tried, useless,

CodePudding user response:

reference 5 floor yusmt reply:

Tried, useless,


Floating - point format specifiers - e, e, f, and g - are not supported. The workaround is to use The StringCchPrintf function to format The Floating - point number into a temporary buffer, then use that buffer as The insert string.

CodePudding user response:

7.3 f, for example, is three decimal floating point number,
  • Related