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 << '\n';
    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

 

posted on 2018-06-20 15:32  nuo267  阅读(94)  评论(0编辑  收藏  举报