实验七 流类库与输入输出

11.7

#include<iostream>
using namespace std;
int main()
{
    ios_base::fmtflags original_flags=cout.flags();//保存现在的格式化参数设置,以便将来恢复这些设置。 
    cout<<812<<'|';
    cout.setf(ios_base::left,ios_base::adjustfield);// 把对齐方式由缺省的右对齐改为左对齐 
    cout.width(10);// 把输出域的宽度由缺省值0改为10 
    cout<<813<<815<<'\n';
    cout.unsetf(ios_base::adjustfield);//清除对齐方式的设置 
    cout.precision(2);
    cout.setf(ios_base::uppercase|ios_base::scientific);//更改浮点数的显示设置 
    cout<<831.0; 
    cout.flags(original_flags);//恢复原来的格式化参数设置 
    return 0;
}
//输出为 812|813 815 
//     8.31E+02

  11.3

 

#include<iostream>
#include<fstream>
using namespace std;
int main(){
	ofstream file1("text.txt") ;
	file1<<"已成功写入文件!";
	file1.close();
	 return 0;
}

  

11-4

#include<iostream>
#include<fstream>
#include<string>
using namespace std;
int main(){
    string  s;
    ifstream in ("text1.txt");
    if (!in) {
        cout  <<  "fail to open."  <<  endl;
        return 1;
    }
    in >> s;
    cout << s << endl;
    in.close() ;
    return 0;
}

  

 最后两条实验题 不是乱码就是打不开小黑框。。就先不贴了 丢人

转载于:https://www.cnblogs.com/wuyijie/p/9205527.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值