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;
}
最后两条实验题 不是乱码就是打不开小黑框。。就先不贴了 丢人