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

庐江县建设网站蓝色清爽网站

庐江县建设网站,蓝色清爽网站,广告公司名字大全最新,wordpress自带ajax很慢目录1、格式化输出1. setw manipulator(“设置域宽”控制符)2. setprecision manipulator(“设置浮点精度”控制符)3. setfill manipulator(“设置填充字符”控制符)4. Formatting Output in File Operation(在文件操作中格式化输入/输出)5.小练习2、用于输入/输出流的函数1. g… 目录1、格式化输出1. setw manipulator(“设置域宽”控制符)2. setprecision manipulator(“设置浮点精度”控制符)3. setfill manipulator(“设置填充字符”控制符)4. Formatting Output in File Operation(在文件操作中格式化输入/输出)5.小练习2、用于输入/输出流的函数1. getline()2. get() and put()3. flush()4.getline()练习 1、格式化输出 1. setw manipulator(“设置域宽”控制符) 要包含头文件 setw(n) 设置域宽即数据所占的总字符数 std::cout std::setw(3) a std::endl; 输出 _ _asetw()控制符只对其后输出的第一个数据有效 std::cout std::setw(5) a b std::endl; 输出 _ _ _ _absetw()的默认为setw(0)按实际输出。 如果输出的数值占用的宽度超过setw(int n)设置的宽度则按实际宽度输出。 float f0.12345;std::cout std::setw(3) f std::endl; 输出 0.123452. setprecision manipulator(“设置浮点精度”控制符) setprecision(int n) (1) 控制显示浮点数的有效位 (2) n代表数字总位数不包括小数点 #include iostream #include iomanip using namespace std;int main() {float f 17 / 7.0;cout f endl;cout setprecision(0) f endl;cout setprecision(1) f endl;cout setprecision(2) f endl;cout setprecision(3) f endl;cout setprecision(6) f endl;cout setprecision(8) f endl;return 0;}VS效果 2.42857 2.42857 2 2.4 2.43 2.42857 2.4285715 3. setfill manipulator(“设置填充字符”控制符) setfill© 设置填充字符即“符号后面的数据长度小于域宽时使用什么字符进行填充。 std::cout std::setfill(*) std::setw(5) a std::endl; 输出 ****a4. Formatting Output in File Operation(在文件操作中格式化输入/输出) 5.小练习 本部分展示内容如下; 任务1展示setw和setfill 1、setw只对紧跟随其后的数据起作用 2、setfill指定填充字符 任务2展示setprecision、fixed、showpoint、left、right 任务3展示hexfloat #include iostream #include iomanipusing std::cout; using std::endl; int main() {//任务1展示setw和setfill//cout std::setw(4) std::setfill(#) a;cout std::setfill(#);for (int i 0;i 5;i){cout std::setw(i2) endl;}//任务2展示setprecision、fixed、showpoint、left、rightdouble pi 3.1415926535897;cout std::setprecision(6) pi endl;//定点数代表了小数点后几位cout std::setprecision(6) std::fixed pi endl;double y 3.0;cout y endl;cout std::showpoint y endl;cout std::setw(20) std::left pi endl;cout std::setw(20) std::right pi endl;//任务3展示hexfloatcout std::hexfloat y endl;cout std::defaultfloat;cout y endl;cout std::showpoint y endl;return 0; }2、用于输入/输出流的函数 1. getline() 运算符用空格分隔数据 对于文件内容 Li Lei#Han Meimei#Adam 如下代码只能读入“Li” ifstream input(name.txt); std::string name; input name;如果用成员函数getline(char* buf, int size, char delimiter)读LiLei constexpr int SIZE{ 40 }; std::arraychar , SIZE name{}; while (!input.eof()) {// not end of fileinput.getline(name[ 0 ] , SIZE , #);std::cout name[ 0 ] std::endl; }如果用非成员函数getline(istream is, string str, char delimiter)读LiLei std::string name2{}; while (!input.eof()) {std::getline(input, name2, #);std::cout n std::endl; }2. get() and put() get: read a character //这一种需要将int类型强制转换为char类型 //char c static_castchar(in.get()); int istream::get(); //char c; in.get(c); istream get (char c);put write a character ostream put (char c);3. flush() 将输出流缓存中的数据写入目标文件 ostream flush();用法 cout.flush(); // 其它输出流对象也可以调用 flush() cout Hello std::flush; // 与endl类似作为manipulator的调用方式4.getline()练习 本部分要展示的内容如下; 任务1展示istream::getline函数的用法 任务2展示std::getline函数的用法 #include iostream #include fstream #include array #include string #include filesystem using std::cout; using std::endl; using std::ifstream; using std::string;int main() {//打开文件std::filesystem::path p{ scores.txt };ifstream in{p};if (!in){cout Cant open file p endl;std::abort();}//任务1istream::getline函数constexpr int SIZE 1024;std::arraychar, SIZE buf; //bufwhile (!in.eof()){in.getline(buf[0], SIZE, #);cout buf[0] endl;}//由于上面的操作已经读到文件末尾此时需要关闭重新打开文件in.close();in.open(p);//任务2std::getline函数的用法std::string name1{};while (!in.eof()){std::getline(in,name1,#);cout name1 endl;}std::cin.get();return 0;}效果 默认情况下getline函数使用换行符作为分隔符
http://wiki.neutronadmin.com/news/216154/

相关文章:

  • 成都网站推广营销设计h5的网站
  • 网站建设中哪些最重要性电脑搭建网站
  • 旅游门户网站源码怎么做的网站空间到期怎么办
  • 如何做网站二级域名做下载网站好不好做
  • 学佛网站开发项目需求分析wordpress免费企业模板
  • 荣耀官方网站wordpress 自适应主题
  • 免费招聘网站有哪些平台xampp部署wordpress
  • 焦作建网站科技设计网站
  • 学网站建设的工资高吗大型门户网站建设多少钱
  • 国外出名设计网站有哪些广东东莞营销
  • 百度网站优化外包惠州网站制作公司哪家好
  • w3c验证网站烈焰传奇网页版
  • 想给大学做网站网站建设改代码改哪些
  • 网站开发招聘需要揭阳网站制作服务
  • 使用python做网站免费签名设计软件
  • 网站seo方案撰写淄博建企业网站
  • 网站建设公司文案关于建筑设计的网站
  • 专业网站设计立找亿企邦重庆建设厅官网
  • 酒类公司网站模板网络课程网站模板
  • 替别人做设计的网站旅游网站建设公司哪家好
  • 网络初始网站wordpress如何设置导航栏
  • 聊城市住房和城乡建设局网站建网站的公司服务
  • 牙克石网站建设哪些网站百度收录快
  • 贵州省城乡建设部网站首页网站网站服务器
  • 关于建设网站的图片怎样建淘宝客网站
  • 深圳市大鹏建设局网站加工企业网站这么做
  • Wordpress翻译文章seo网站推广方式
  • 新乡微网站建设好商网
  • 企业网站建设网站制作营销网站建设评估与分析
  • 网站建设服务费会计分录服装设计网站免费