The statement in format is too long and wants a newline

dtongwei 注册会员
2023-02-26 15:04

This answer partially references GPT, GPT_Pro to better solve the problem.
format if the statement in the function is too long, use parentheses to wrap the line, so that the code is clearer and easier to read. For example:

Info FormatL_T(
    %d    % .3f),

breaks a long sentence into multiple lines in parentheses to make code easier to read. Also, the statements in the format function do not need to be immediately followed and can have Spaces between them to work. For example:

Info FormatL_T( %d,   % .3f), 2.1234);

This is also OK.

Also, if you want to break the output into multiple lines, you can use \n in format to do this. For example:
Info FormatL_T("%d\n% .3f", 2.1234);

Use \n to insert a new line into the output. However, if you want to output text that contains \n, you escape the character by prefacing it with a backslash(\). For example:

Info FormatL_T("%d\\n% .3f", 2.1234);

This will print \n in the string correctly. In general, when the format function is too long, brackets can be used to make the code easier to read; If you want to insert a new line into the output, you can do so using \n.
If the answer is helpful, please accept it.

dengkun1981922 注册会员
2023-02-26 15:04

Write based on Monster group and GPT:
When using a formatted string, it is not possible to implement line breaks with \n because it is just an ordinary character and cannot be resolved to line breaks.

If you want to wrap the output string, you can split a longer string into multiple lines, either by using a multiline string(enclosed in double quotes) or by using the concatenation operator +.

Here is an example of a multi-line string:

                "\n"),  // 在此处添加换行符
                2, 1234);

Here is an example of using the join operator:

Info.Format(_T("%d,%.3f" // 注意:连接运算符不能在字符串之间添加空格
                "\n"),  // 在此处添加换行符
                2, 1234);

uses a backslash \ to split a long string into multiple lines, or adds a concatenation operator + at the end of the string to concatenate the string on the next line. This allows for line wrapping in the output string.

About the Author

Question Info

Publish Time
2023-02-26 15:04
Update Time
2023-02-26 15:04