zoukankan      html  css  js  c++  java
  • 第七次实验

    //11-7 
    #include<iostream>
    using namespace std;
    int main()
    {
        ios_base::fmtflags original_flags=cout.flags();
    //    flag指针?指向开头? 
        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);
    //  科学计数法表示,并且小数点后保留两位有效数字 
        cout<<831.0;
        cout.flags(original_flags);    
        return 0;
    }

    //11-8 
    #include<fstream>
    #include<iostream>
    #include<string>
    using namespace std;
    int main()
    {
        ofstream fout("text1.txt");
        if(!fout){
            cout << "fail to build" << endl;
            return 0;
        }
        fout << "已成功写入文件!";
        fout.close();
        return 0;
    }

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

    //应用练习1
    #include<iostream> #include<fstream> #include<vector> #include<ctime> #include<string> using namespace std; struct stu { string i1; string i2; string i3; string i4; }; int main() { ifstream fin("list.txt"); stu k; vector<stu> tar; if(!fin){ cout << "fail to open"<<endl; return 0; } string i1,i2,i3,i4; while(fin >> i1 >> i2 >> i3 >> i4){ k.i1=i1,k.i2=i2,k.i3=i3,k.i4=i4; tar.push_back(k); } fin.close(); vector<stu> d; srand((unsigned)time(NULL)); while(d.size()<5){ d.push_back(tar[rand()%83]); } ofstream fout("roll.txt"); for(int i=0;i<d.size();i++){ fout << d[i].i1 << " " << d[i].i2 << " "; fout << d[i].i3 << " " << d[i].i4 << endl; } fout.close(); return 0; }

    //应用练习2
    #include<iostream> #include<string> #include<fstream> using namespace std; int main() { ifstream fin1("num1.txt"); char ch,prech=' '; int line=0,word=0,words=0; while((ch=fin1.get())!=EOF){ if(ch==' ')line++; if(ch!=' '&&ch!=' ')word++; if((prech==' '&&ch!=' ')||(prech==' '&&ch!=' '))words++; prech=ch; } cout << "num.txt has "<< word << " word" << endl; cout << "num.txt has "<< words << " words" << endl; cout << "num.txt has "<< line << " line" << endl; return 0; }

  • 相关阅读:
    基于 OAI 部署私有的 4G EPS
    Ubuntu Snap 简述
    OAI SDR LTE 基站部署
    企业文化二三谈
    OpenStack 的 SR-IOV 虚拟机热迁移
    在 ThinkPad E470 上安装 Ubuntu 16.04 无线网卡驱动
    读写可编程 SIM/USIM 卡
    4G LTE/EPC UE 的附着与去附着
    4G EPS 的网络协议栈
    Java- 类型转换
  • 原文地址:https://www.cnblogs.com/tacore/p/9206166.html
Copyright © 2011-2022 走看看