C++ 实验七

#include <iostream>
#include <fstream>
using namespace std;

int main(){
 ofstream file;
 file.open("E:\text.txt");
 file << "已成功写入文件!" << endl;
 file.close();
 return 0;
} 
11-3

#include <iostream>
#include<string>
#include <fstream>
using namespace std;

int main(){
    string temp;
 ifstream file;
 file.open("E:\text.txt");
 while (getline(file, temp) ){     //每当读取一行的时候
     cout << temp<<endl;    //输出那一行的内容(已经知道是字符串了)
 };
 file.close();
 system("pause");
 return 0;
} 
11-4

#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);                                     //设置输出宽度为10字符
    cout << 813 << 815 << '
';
    cout.unsetf(ios_base::adjustfield);                 //取消设置格式
    cout.precision(2);
    cout.setf(ios_base::uppercase | ios_base::scientific);  //对于科学格式显示大写字母E,以科学格式显示浮点数值
    cout << 831.0;
    cout.flags(original_flags);                         //恢复初始的的格式

    return 0;
} 
11-7
原文地址:https://www.cnblogs.com/nuo26/p/9175784.html