美文网首页
13 文件的输出设置

13 文件的输出设置

作者: LuckTime | 来源:发表于2016-06-18 09:57 被阅读18次

// fill ostream

include <iostream>

include <fstream>

include <iomanip>

include <string>

using namespace std;
class WF
{
int i;
char f;
public:
WF(int i,char f) :i(i),f(f){}

friend ostream& operator<<(ostream& os,WF o)
{
os.width(o.i);
os.fill(o.f);
return os;
}
};
int main()
{
cout.width(10);//fill ten bytes screen.
cout << 123 << endl;//width only used next time//宽度填充仅对下一次输出有效
cout << 123 << endl;
cout.width(1); //fill one byte screen
cout << 123 << endl;
cout.width(10);
cout.fill(''); //free space used of ‘’.often used ..until the end of the program
cout <<123<<endl;
cout.width(10);
cout << 123 << endl;
cout.precision(8);//set precision //设置精度
cout << (double)123.0 <<endl;
//often see output control sign
cout.setf(ios::left); //left 向左对齐

cout.setf(ios:: right | ios::showpos);
cout.setf(ios::scientific | ios::uppercase);
cout << WF(8,'') << 123 <<endl;
cout.unsetf(ios::scientific | ios::uppercase);
cout.unsetf(ios:: right | ios::showpos);
//====================================
cout << setw(10) << setfill('~') << left << 123 << endl;
cout << setw(10) << setfill('+') << right << 123 << endl;
//================================
string str;
str = "hello";
cout << sizeof(str) <<endl;
str = "hello,world!";
cout << sizeof(str) <<endl; //输出结果一样,sizeof只注重类型,不关注内容。。是指针
//ofstream fout("app.txt",ios::app);//add to the file end//追加在文件后面 //顺序读写方法
//seekg(位置 int)跳着读写方法
//getline(cin,str);
ofstream fout("seek.txt",ios::out | ios::binary);
fout << "hello,sd0705!" <<endl;
fout.seekp(0);//first write H
fout.put('H');
fout.seekp(7);
fout <<"S";
fout << str << endl;
fout.close();
/

ios::right //右对齐
/========
ios::dec
ios::oct
ios::hex
/========
ios::showbase// take prefix output 带着前缀输出
ios::showpoint //take point output 带着小数点输出
ios::scientific //science output 科学输入法输出 3.5 e 9
ios::uppercase // uppercase 大写输出
ios::showpos// use sign output //使用符号输出
ios::app //start writing at end of file
ios::ate //start reading or writing at end of file
ios::in //open for reading
ios::trunc //truncate file to zero length if exists
ios::nocreate //erroe when opening if file does not exist
ios::noreplace :error when opening for output if file exist
ios::binary //open file in binary mode
ios::out //open for writing
/=======
//flush :clear out buffer
endl: insert a '\n' and clear out buffer
oct:set the output as oct
dec
hex
{
setw(宽度)
setfill(填充字符)
setprecision(精度)
必须有头文件 <iomanip>
}
/
//cout.left
//=======================after revision
/
char ch;
int num;
cout << "cin num and char" << endl;
cin >> num >> ch;
cout << WF(num,ch) << 123 <<endl; //must have output //必须有输出
*/

}

相关文章

  • 13 文件的输出设置

    // fill ostream include include incl...

  • 设置输出的文件名

    在build.gradle中的android下添加

  • CD-HIT学习

    CD-hit 参数解读 -i 设置输入文件 -o 设置输出文件,可以将每次分析的ID阈值放到名称中,方便以后使用,...

  • 2020-01-25【转录组】五、featureCounts对比

    -T 线程 -p 双端 -a 注释文件gtf -o 输出文件 我设置了24线程,感觉...

  • Xcode多依赖库编译和打包

    1.设置编译文件输出路径。 打开Xcode-Preferences,选中Location标签页,设置Derived...

  • 【蓝桥杯 入门训练 序列求和】

    划重点!!输出有效位数设置:引用头文件#include 下的setprecision() ------------...

  • Go beego的logs源码解读

    beego的日志处理支持多种引擎、多种日志级别的输出,也可以设置输出方式(包括是否输出文件名和行号、同步输出或者异...

  • AMBER轨迹分析

    如果在运行分子动力学的时候,轨迹文件的步长设置的太短,或者输出文件输出的太频繁,这样会导致生成的nc文件非常大,此...

  • 如何处理Bernese BPE运行错误?

    检查工程设置是否正确。 检查时段设置是否正确。 检查BPE输出文件(“^OUTPUT”按钮)。 从BPE检查协议文...

  • FFmpeg - 音频重采样

    音频重采样步骤 创建采样上下文 设置输入缓冲区 设置输出缓冲区 打开文件开始重采样 检查输出缓冲区是否还有残余的样...

网友评论

      本文标题:13 文件的输出设置

      本文链接:https://www.haomeiwen.com/subject/wnnvdttx.html