C ++中的格式说明符 [英] Format Specifier In C++

查看:149
本文介绍了C ++中的格式说明符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello All, I'm posting this question after searching Google, but didn't quite understand. In the following code





CString str1;
str1.Format(_T("%%02d°%%02d'%%1.%dlf\""), val)
//val is an integer





This displays decimal degrees, minutes and seconds. But in the seconds part why is it 1.%dlf, why is the decimal, long n float used and also from my understanding %% means print the percentage but the % symbol is not displayed in my interface.

推荐答案

我相信您粘贴到那里的内容只会生成一个格式字符串(但它缺少一个整数"参数)

str1.Format(_T("%%02d°%%02d''%%1.%dlf\""), 5);

会给你:
%02d°%02d''%1.5lf"

我认为这样做是为了可以动态修改小数位数(在示例中,参数5可以更改).创建该字符串之后,可能会使用它来格式化实际的字符串.

例如:
str2.Format(str1, 1,2,3.45678910);

这将导致类似以下内容:
01°02''3.45679"
I believe what you pasted there will simply generate a format string (btw it is missing an "integer" parameter)

str1.Format(_T("%%02d°%%02d''%%1.%dlf\""), 5);

will give you:
%02d°%02d''%1.5lf"

I supose this is done so the number of decimals can be dynamically modified (in the example the parameter 5 can be varied). After that string has been created, it is probably used to format the actual string.

E.g:
str2.Format(str1, 1,2,3.45678910);

which will result in something like:
01°02''3.45679"


这篇关于C ++中的格式说明符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆