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

考幼师证去哪个网站做试题营销策略怎么写范文

考幼师证去哪个网站做试题,营销策略怎么写范文,哈尔滨网站建设费用,网站建设广告目录 std::cout 格式化输出简介使用成员函数使用流操作算子 std::cout 格式化输出简介 C 通常使用cout输出数据,和printf()函数相比,cout实现格式化输出数据的方式更加多样化; 一方面,cout 作为 ostream 类的对象,该类…

目录

        • std::cout 格式化输出简介
        • 使用成员函数
        • 使用流操作算子

std::cout 格式化输出简介

C++ 通常使用cout输出数据,和printf()函数相比,cout实现格式化输出数据的方式更加多样化;
一方面,cout 作为 ostream 类的对象,该类中提供有一些成员方法,可实现对输出数据的格式化;另一方面,为了方面用户格式化输出数据,C++ 标准库专门提供了一个 <iomanip> 头文件,该头文件中包含有大量的格式控制符,也就是流操作算子,使用上更加方便;
cout 格式化输出有两种方法,一种是直接使用成员函数,另一种是使用流操作算子,下面分别进行介绍:

使用成员函数

cout 的基类是 ostream 类,ostream 类 中还包含一些可实现格式化输出的成员方法,这些成员方法都是从 ios 基类(以及 ios_base类)中继承来的,cout(以及 cerrclog)也能调用:

成员函数说明
flags(fmtfl)当前的格式全部替换为fmtfl,fmtfl 可以是一种格式,也可以是多种格式
precision(n)设置输出浮点数的精度为 n
width(w)指定输出宽度为 w 个字符
fill(c)在指定输出宽度的情况下,输出宽度不足用 c 填充
setf(fmtfl, mask)在当前格式的基础上,追加 fmtfl 格式,并且删除 mask 格式,其中mask参数可以省略
unsetf(mask)在当前格式的基础上,删除 mask 格式

对于上面函数中的 flags 函数的fmtfl参数,setf() 函数中的 fmtfl 参数以及 unsetf() 函数可以选择下面的值:

标志作用
ios::boolapha把 true 和 false 输出为字符串
ios::left输出数据在本域宽范围内向左对齐
ios::right输出数据在本域宽范围内向右对齐
ios::internal数值的符号位在域宽内左对齐,数值右对齐,中间由填充字符填充
ios::dec设置整数的基数为 10
ios::oct设置整数的基数为 8
ios::hex设置整数的基数为 16
ios::showbase强制输出整数的基数(八进制数以 0 开头,十六进制数以 0x 打头)
ios::showpoint强制输出浮点数的小点和尾数 0
ios::uppercase在以科学记数法格式 E 和以十六进制输出字母时以大写表示
ios::showpos对正数显示“+”号
ios::scientific浮点数以科学记数法格式输出
ios::fixed浮点数以定点格式(小数形式)输出
ios::unitbuf每次输出之后刷新所有的流

setf(fmtfl, mask)unsetf(fmtfl, mask) 中的mask 参数,可以传递为下面的几个:

标志作用
ios::adjustfieldios::left , ios::right , ios::internal
ios::basefieldios::dec ,ios::oct ,ios::hex
ios::floatfieldios::scientific , ios::fixed

使用 cout 成员函数的示例程序如下:

bool testCoutUsingflags() {{// setf(fmt,mask) 在当前格式的基础上追加 fmt flag, 并且删除 mask 格式std::cout.setf(std::ios::boolalpha);bool a = true;std::cout << "bool a:" << a << std::endl;int m = 100;std::cout.setf(std::ios::hex, std::ios::basefield);std::cout << "int m:" << m << " bool a " << a << std::endl;// 去除相应的标志std::cout.unsetf(std::ios::boolalpha);std::cout << "hex print int m:" << m << " bool a " << a << std::endl;std::cout.setf(std::ios::dec, std::ios::basefield);int n = 0x110;std::cout << "dec print int n:" << n << std::endl;std::cout.setf(std::ios::oct, std::ios::basefield);std::cout.setf(std::ios::showbase);std::cout << "oct print int n:" << n << std::endl;}{std::cout.setf(std::ios::fixed, std::ios::floatfield);float f = 1 / 3.0f;std::cout << "float f in fixed is:" << f << std::endl;std::cout.precision(10);std::cout << "float f precision 10 in fixed is:" << f << std::endl;std::cout.setf(std::ios::scientific, std::ios::floatfield);std::cout.precision(3);std::cout << "float f in scientific is:" << f << std::endl;std::cout.setf(std::ios::uppercase);std::cout << "float f in scientific uppercase is:" << f << std::endl;}{std::cout.width(50);std::cout.fill('_');std::cout.setf(std::ios::left, std::ios::adjustfield);std::cout << "this is my demo" << std::endl;std::cout.unsetf(std::ios::adjustfield);std::cout.width(50);std::cout.fill('_');std::cout.setf(std::ios::right, std::ios::adjustfield);std::cout << "this is my demo" << std::endl;}return true;
}

输出结果如下:

bool a:true
int m:64 bool a true
hex print int m:64 bool a 1
dec print int n:272
oct print int n:0420
float f in fixed is:0.333333
float f precision 10 in fixed is:0.3333333433
float f in scientific is:3.333e-01
float f in scientific uppercase is:3.333E-01
this is my demo___________________________________
this is my demo
this is my demo
使用流操作算子

流操作算子实在iomanip中定义的,要使用这些流操作算子,必须包含此头文件:

注意下面的 *号,表示默认使用的算子,比如: 在默认情况下,整数使用十进制形式输出

流操作算子作用
*dec以十进制形式输出整数
hex以十六进制形式输出整数
oct以八进制形式输出整数
fixed以小数形式输出浮点数
scientific以科学计数法计数形式输出浮点数
left左对齐,宽度不足的时候填充字符到右边
*right右对齐,宽度不足的时候填充字符到左边
setbase(b)设置输出整数的进制,b=8、10或者16
setw(w)指定输出宽度为w个字符,或者输入字符串读取w个字符
setfill(c)指定输出宽度的情况下,输出宽度不足用字符c填充(默认是使用空格填充)
setprecision(n)输出浮点数的精度为 n, 就是小数点后应该暴露的位数
boolaplha把 true 和 false 输出为字符串
noboolalpha把true 和 false 输出为0,1
showbase输出数值进制的前缀
noshowbase不输出数值进制的前缀
showpoint总是输出小数点
*noshowpoint只有当小数部分存在时才显示小数点
showpos在非负数中显示+
*noshowpos在非负数中不显示+
uppercase十六进制使用 A~E,设置显示前缀,那么前缀输出为0X
*nouppercase十六进制使用 a~e,设置显示前缀,那么前缀输出为0x

使用流操作算子控制输出的综合程序如下:

bool testCoutUsingStreamflags() {// stream operation flag will take effect all time util you set another flagbool a = false;std::cout << "bool a:" << std::boolalpha << a << std::endl;std::cout << "bool a:" << std::noboolalpha << a << std::endl;// showbase and dec oct & hexint m = 80;std::cout <<"dec int m:" << std::dec << std::showbase << m << std::endl;std::cout << "hex int m:" << std::hex << std::showbase << m << std::endl;std::cout << "oct int m:" << std::oct << std::showbase << m << std::endl;// std::showpos 显示 + -std::cout << "dec int m:" << std::dec << std::showbase << std::showpos << m << std::endl;// setw and setfillstd::cout << std::left << std::setw(50) << std::setfill('_') << "hello world" << std::endl;std::cout << std::right << std::setw(50) << std::setfill('_') << "hello world" << std::endl;std::cout << std::internal << std::setw(50) << std::setfill('_') << "hello world m:" << m << std::endl;std::cout << std::noshowpos << std::endl;int n = 100;std::cout << std::setbase(16) << std::showbase << "int n:" << n << std::endl;float f = 1 / 3.0f;// 0.333333std::cout << std::fixed << "f = " << f << std::endl;// 0.33333std::cout << std::fixed << std::setprecision(5) << "f = " << f << std::endl;// 3.33333e-1std::cout << std::scientific << std::setprecision(5) << "f = " << f << std::endl;// 3.33333E-1std::cout << std::scientific << std::uppercase << std::setprecision(5) << "f = " << f << std::endl;// std::showpoint 强制输出浮点数的小点和尾数0 std::cout << std::fixed << std::showpoint << std::setprecision(5) << "f = " << f << std::endl;{// print pointer 指针有做特殊的处理int* ptr = new int(10);std::cout << std::showbase << std::hex << ptr << std::endl;std::cout << std::showbase << std::hex << reinterpret_cast<intptr_t*>(ptr) << std::endl;delete ptr;}return true;
}

输出结果如下:

basic test main enter
basicCplusplusCout::testbasicCplusplusCoutImpl enter
bool a:false
bool a:0
dec int m:80
hex int m:0x50
oct int m:0120
dec int m:+80
hello world_______________________________________
_______________________________________hello world
____________________________________hello world m:+80int n:0x64
f = 0.333333
f = 0.33333
f = 3.33333e-01
f = 3.33333E-01
f = 0.33333
000001E419046150
000001E419046150
http://www.fp688.cn/news/160084.html

相关文章:

  • 威宁建设局网站seo实战论坛
  • 网站建设中 显示 虚拟机防恶意竞价点击软件
  • 有限公司技术支持 东莞网站建设百度推广要多少钱
  • 校园网站模板西安网站外包
  • 榆次住房保障和城乡建设局网站西安seo霸屏
  • 学生做网站的目的嘉兴网站建设
  • 怎么弄个人网站搜狗友链交换
  • 东莞百度网站快速排名口碑营销的形式
  • 无锡网站建设专家无锡网站制作有创意的营销案例
  • wordpress搭建网站seo基础培训教程
  • 这样做微信网站温州seo优化公司
  • 郑州小型网站制作公司定制企业网站建设制作
  • 收录网站源码seo服务收费
  • 专门做壁纸的网站百度优化点击软件
  • 网站宽屏版深圳网络营销全网推广
  • 我想注册一个做门窗的网站应该怎样做微信小程序免费制作平台
  • seo软件哪个好优化大师app
  • wordpress分享积分企业网站seo方案
  • 电脑iis做网站搜索引擎seo如何赚钱
  • 做封面的地图网站百度网盘在线观看资源
  • 葫芦岛做网站公司电脑培训机构
  • 网站的整合如何搭建网站
  • 如何做阅读网站河南网站关键词优化代理
  • 政务公开 加强门户网站建设惠州搜索引擎seo
  • 北京网站建设百度排名内蒙古网站seo
  • 郑州哪家网站建设好游戏推广赚佣金平台
  • 实体店做团购有那些网站seo引擎
  • 学校网站建设设想东莞网站设计公司排名
  • 山东做网站建设的好公司北京网站优化服务商
  • jsp网站开发的环境要求百度网址大全电脑版旧版本