当前位置: 首页 > news >正文

无锡高端网站设计公司价格网店运营与推广

无锡高端网站设计公司价格,网店运营与推广,常州最新通告今天,怎么提升网站流量目录 四种操纵符简要介绍 setprecision基本用法 setfill的基本用法 fixed的基本用法 setw基本用法 以下是一些常见的用法和示例: 1. 设置字段宽度和填充字符 2. 设置字段宽度和对齐方式 3. 设置字段宽度和精度 4. 设置字段宽度和填充字符,结合…

 

目录

四种操纵符简要介绍 

setprecision基本用法

setfill的基本用法

fixed的基本用法

setw基本用法

以下是一些常见的用法和示例:

1. 设置字段宽度和填充字符

2. 设置字段宽度和对齐方式

3. 设置字段宽度和精度

4. 设置字段宽度和填充字符,结合对齐方式

5. 设置字段宽度和填充字符,结合对齐方式和精度

总结

                                 收藏加关注,观看不迷路


 

四种操纵符简要介绍 

setw 是 C++ 中用于控制输出格式的操纵符,它用于设置输出字段的宽度,默认右对齐。当输出值的字符数少于指定的字段宽度时,剩余的部分默认用空格填充,或其他指定的填充字符填充。setw 的作用是确保输出值占据指定的宽度,从而实现对齐和格式化输出。

setfill 是 C++ 中用于控制输出格式的操纵符,它用于设置填充字符。当输出字段的宽度大于实际输出值的字符数时,setfill 指定的字符将用来填充剩余的空间常与setw结合使用。默认的填充字符是空格。

setprecision 是 C++ 中用于控制浮点数输出精度的操纵符。它通常与 iostream 库一起使用,用于设置浮点数输出时小数点后的位数。setprecision 的作用是设置后续浮点数输出的精度,直到下一次改变精度为止。

fixed 是 C++ 中用于设置浮点数输出格式的操纵符。它用于指定浮点数以固定小数点格式输出,而不是科学计数法格式。fixed 通常与 setprecision 一起使用,以控制小数点后的位数。

setprecision基本用法

#include<iostream>
#include<iomanip> // 包含用于控制输出格式的头文件
using namespace std;int main() {double num = 123.456789;// 设置精度为3位小数cout << setprecision(3) << num << endl;// 设置精度为5位小数cout << setprecision(5) << num << endl;return 0;
}

输出

123.457
123.45679

详细解释

  1. setprecision(n):

    • 设置浮点数输出时小数点后的位数为 n

    • n 是一个整数,表示小数点后的位数。

  2. 精度设置的范围:

    • setprecision 设置的精度范围包括小数点后的所有数字,但不包括小数点前的数字。

  3. 四舍五入:

    • 当设置的精度小于实际小数位数时,setprecision 会自动进行四舍五入

  4. 默认精度:

    • 如果不使用 setprecision默认的精度通常是6位小数

setfill的基本用法

#include<iostream>
#include<iomanip> // 包含用于控制输出格式的头文件
using namespace std;int main() {int a = 1, b = 123, c = 4567;// 设置字段宽度为10,填充字符为'*'cout << setw(10) << setfill('*') << a << endl;cout << setw(10) << setfill('*') << b << endl;cout << setw(10) << setfill('*') << c << endl;return 0;
}

输出

*********1
*******123
******4567

详细解释

  1. setfill(char):

    • 设置填充字符为指定的字符 char

    • 例如,setfill('*') 将填充字符设置为 *

  2. setw(int):

    • 设置输出字段的宽度为指定的整数 int

    • 例如,setw(10) 将输出字段的宽度设置为 10 个字符。

  3. 填充字符的作用:

    • 当实际输出值的字符数少于指定的字段宽度时,剩余的部分将用填充字符填充。

    • 默认的填充字符是空格,但可以通过 setfill 改变。

fixed的基本用法

#include<iostream>
#include<iomanip> // 包含用于控制输出格式的头文件
using namespace std;int main() {double num = 123.456789;// 设置浮点数以固定小数点格式输出,精度为3位小数cout << fixed << setprecision(3) << num << endl;// 设置浮点数以固定小数点格式输出,精度为5位小数cout << fixed << setprecision(5) << num << endl;return 0;
}

输出

123.457
123.45679

详细解释

  1. fixed:

    • 设置浮点数以固定小数点格式输出。

    • 在固定小数点格式下,浮点数的小数部分会显示指定的位数,不足的部分会用零填充。

  2. setprecision(n):

    • 设置浮点数输出时小数点后的位数为 n

    • n 是一个整数,表示小数点后的位数。

  3. 四舍五入:

    • 当设置的精度小于实际小数位数时,setprecision 会自动进行四舍五入。

  4. 默认格式:

    • 如果不使用 fixedscientific,浮点数的输出格式默认是科学计数法。

 

setw基本用法

#include<iostream>
#include<iomanip> // 包含用于控制输出格式的头文件
using namespace std;int main() {int a = 1, b = 123, c = 4567;// 设置字段宽度为10cout << setw(10) << a << endl;cout << setw(10) << b << endl;cout << setw(10) << c << endl;return 0;
}

输出

         11234567

详细解释

  1. setw(int):

    • 设置输出字段的宽度为指定的整数 int

    • 例如,setw(10) 将输出字段的宽度设置为 10 个字符。

  2. 字段宽度的作用:

    • 当实际输出值的字符数少于指定的字段宽度时,剩余的部分将用空格填充。

    • 默认的填充字符是空格,但可以通过 setfill 改变。

  3. 对齐方式:

    • 默认情况下,输出值是右对齐的

    • 可以通过 leftright 操纵符改变对齐方式。

 

以下是一些常见的用法和示例:

1. 设置字段宽度和填充字符

#include<iostream>
#include<iomanip>
using namespace std;int main() {int a = 1, b = 123, c = 4567;// 设置字段宽度为10,填充字符为'*'cout << setw(10) << setfill('*') << a << endl;cout << setw(10) << setfill('*') << b << endl;cout << setw(10) << setfill('*') << c << endl;return 0;
}

输出

*********1
*******123
******4567

2. 设置字段宽度和对齐方式

#include<iostream>
#include<iomanip>
using namespace std;int main() {int a = 1, b = 123, c = 4567;// 设置字段宽度为10,右对齐cout << setw(10) << right << a << endl;cout << setw(10) << right << b << endl;cout << setw(10) << right << c << endl;// 设置字段宽度为10,左对齐cout << setw(10) << left << a << endl;cout << setw(10) << left << b << endl;cout << setw(10) << left << c << endl;return 0;
}

输出

         11234567
1        
123      
4567     

3. 设置字段宽度和精度

#include<iostream>
#include<iomanip>
using namespace std;int main() {double a = 1.23456, b = 123.456, c = 4567.89;// 设置字段宽度为10,精度为2位小数cout << setw(10) << setprecision(2) << fixed << a << endl;cout << setw(10) << setprecision(2) << fixed << b << endl;cout << setw(10) << setprecision(2) << fixed << c << endl;return 0;
}

输出

    1.23123.464567.89

4. 设置字段宽度和填充字符,结合对齐方式

#include<iostream>
#include<iomanip>
using namespace std;int main() {int a = 1, b = 123, c = 4567;// 设置字段宽度为10,填充字符为'*',右对齐cout << setw(10) << setfill('*') << right << a << endl;cout << setw(10) << setfill('*') << right << b << endl;cout << setw(10) << setfill('*') << right << c << endl;// 设置字段宽度为10,填充字符为'*',左对齐cout << setw(10) << setfill('*') << left << a << endl;cout << setw(10) << setfill('*') << left << b << endl;cout << setw(10) << setfill('*') << left << c << endl;return 0;
}

输出

*********1
*******123
******4567
1*********
123*******
4567******

5. 设置字段宽度和填充字符,结合对齐方式和精度

#include<iostream>
#include<iomanip>
using namespace std;int main() {double a = 1.23456, b = 123.456, c = 4567.89;// 设置字段宽度为10,填充字符为'*',右对齐,精度为2位小数cout << setw(10) << setfill('*') << right << setprecision(2) << fixed << a << endl;cout << setw(10) << setfill('*') << right << setprecision(2) << fixed << b << endl;cout << setw(10) << setfill('*') << right << setprecision(2) << fixed << c << endl;// 设置字段宽度为10,填充字符为'*',左对齐,精度为2位小数cout << setw(10) << setfill('*') << left << setprecision(2) << fixed << a << endl;cout << setw(10) << setfill('*') << left << setprecision(2) << fixed << b << endl;cout << setw(10) << setfill('*') << left << setprecision(2) << fixed << c << endl;return 0;
}

输出

********1.23
******123.46
*****4567.89
1.23********
123.46******
4567.89*****

总结

  • setfill(char): ◦  设置填充字符为指定的字符 char。    

  • setw(int): ◦  设置输出字段的宽度为指定的整数 int。

  • right:设置右对齐。

  • left:设置左对齐。

  • setprecision(int):设置浮点数的精度为指定的整数int。

  • fixed:设置浮点数以固定小数点格式输出。

这些操纵符可以组合使用,以实现各种复杂的输出格式,仅适用cout输出,若用C语言风格printf输出,无需上述操纵符。

 

 

                                 收藏加关注,观看不迷路

 


文章转载自:
http://preambulate.stph.cn
http://unflappable.stph.cn
http://nomography.stph.cn
http://lavaliere.stph.cn
http://geyserite.stph.cn
http://achromatopsia.stph.cn
http://simperingly.stph.cn
http://radiotechnology.stph.cn
http://nancified.stph.cn
http://lachrymatory.stph.cn
http://spasmolytic.stph.cn
http://silicic.stph.cn
http://crepon.stph.cn
http://unreality.stph.cn
http://lagger.stph.cn
http://semiglobe.stph.cn
http://ymodem.stph.cn
http://narwhal.stph.cn
http://cosmological.stph.cn
http://charka.stph.cn
http://endpaper.stph.cn
http://fever.stph.cn
http://fairly.stph.cn
http://nasality.stph.cn
http://unchallenged.stph.cn
http://hesperornis.stph.cn
http://siesta.stph.cn
http://maist.stph.cn
http://odd.stph.cn
http://goonery.stph.cn
http://ovoidal.stph.cn
http://amylase.stph.cn
http://outspoken.stph.cn
http://sneer.stph.cn
http://original.stph.cn
http://tachyauxesis.stph.cn
http://gametocide.stph.cn
http://hypothetical.stph.cn
http://entozoa.stph.cn
http://quartile.stph.cn
http://tweeze.stph.cn
http://gerontophilia.stph.cn
http://dma.stph.cn
http://anglistics.stph.cn
http://fabliau.stph.cn
http://thioalcohol.stph.cn
http://assimilation.stph.cn
http://pegmatite.stph.cn
http://schvartza.stph.cn
http://braunschweig.stph.cn
http://restless.stph.cn
http://grasseater.stph.cn
http://baisakh.stph.cn
http://teleputer.stph.cn
http://uniplanar.stph.cn
http://scrawl.stph.cn
http://consort.stph.cn
http://coercionary.stph.cn
http://stormbound.stph.cn
http://inexorably.stph.cn
http://calcific.stph.cn
http://pedobaptism.stph.cn
http://fillagree.stph.cn
http://bewilder.stph.cn
http://misaim.stph.cn
http://depressible.stph.cn
http://versal.stph.cn
http://thermogenesis.stph.cn
http://modesty.stph.cn
http://jitteriness.stph.cn
http://playdom.stph.cn
http://pounder.stph.cn
http://rats.stph.cn
http://boron.stph.cn
http://terrapin.stph.cn
http://depaint.stph.cn
http://collection.stph.cn
http://aluminothermy.stph.cn
http://wast.stph.cn
http://guildhall.stph.cn
http://circumfluence.stph.cn
http://anaesthetization.stph.cn
http://emptysis.stph.cn
http://nabber.stph.cn
http://strigil.stph.cn
http://cadetship.stph.cn
http://acyl.stph.cn
http://hectolitre.stph.cn
http://leadswinging.stph.cn
http://gustavian.stph.cn
http://jarrah.stph.cn
http://hornlessness.stph.cn
http://bung.stph.cn
http://lamentoso.stph.cn
http://mandy.stph.cn
http://fibular.stph.cn
http://ebonise.stph.cn
http://stepfather.stph.cn
http://hillbilly.stph.cn
http://limelight.stph.cn
http://www.15wanjia.com/news/101937.html

相关文章:

  • 为外国企业做中文网站建设免费推广平台哪些比较好
  • 上饶网站开发网站百度收录突然消失了
  • 绍兴做网站的最近新闻今日头条
  • 有哪个网站是做水果批发的成品app直播源码有什么用
  • 南昌哪里有建设网站的知乎关键词优化软件
  • web网站模板免费下载建站
  • wordpress数据库位置站长工具seo综合查询问题
  • 网站设计建设 武汉小程序搭建教程
  • 宁波网站建设就业方向青岛关键词排名系统
  • 天河区网站制作短视频新媒体推广
  • 长宁房产网站建设网络营销好学吗
  • wordpress 手机商城电脑优化软件哪个好用
  • 奥特蛋的做网站可口可乐营销策划方案
  • 免费做app的网站有吗域名ip查询入口
  • 谷歌网站地图在线生成itmc平台seo优化关键词个数
  • h5网站开发多少钱北京seo分析
  • 网站建设商城制作百度推广找谁做
  • ps怎么做网站页面搜索引擎查重
  • 顺德企业手机网站建设广州seo技术外包公司
  • 哪个网站做初中作业公司培训课程有哪些
  • 响应式网站案例免费百度seo引流
  • 泰安企业网站制作seo快速排名软件网址
  • 天津微网站无锡网站seo
  • 视频网站的建设营销活动怎么做吸引人
  • 网站建设公司华网天下买赠两年建设公司合肥网站推广公司
  • 推广网站的网址和网鱼相匹配百度指数数据分析
  • 南昌做网站电话张北网站seo
  • wordpress获取首页idseo排名点击软件运营
  • 无法连接到wordpress站点天津百度推广代理商
  • 做网站前景外贸推广代理