c++學習,實驗七

來源:互聯網
上載者:User

標籤:fst   spl   字元   cas   大寫   AC   lap   保留   flags   

一,

#include<iostream>using namespace std;int main(){    ios_base::fmtflags original_flags=cout.flags();     cout<<812<<‘|‘;    //輸出數字812和字元|     cout.setf(ios_base::left,ios_base::adjustfield);    // ios_base::left表示下一次輸出時要靠左對齊    // ios_base::adjustfield表示取消之前設定的對齊     cout.width(10);    //指定輸出寬度為 10     cout<<813<<815<<‘\n‘;    //輸出 813,815並換行     //其中 ios_base::left僅生效一次     cout.unsetf(ios_base::adjustfield);    cout.precision(2);    //保留小數點後 2位     cout.setf(ios_base::uppercase|ios_base::scientific);    // ios_base::scientific指使用科學記號標記法    // ios_base::uppercase指使用科學記號標記法時顯示大寫字母 E     cout<<813.0;    //輸出數 813.0     cout.flags(original_flags);     return 0;}
1

二,

#include<iostream>#include<fstream>using namespace std;int main(){    ofstream file("text1.txt");    if(!file){        cout<<"failed"<<endl;        return 1;    }    file<<"已成功寫入檔案!"<<endl;    file.close();    return 0;}
2

三,

#include<iostream>#include<fstream>#include<string>using namespace std;int main(){    string temp;    ifstream a("text1.txt");    if(!a){        cout<<"failed"<<endl;    }    a >> temp;    cout<<temp<<endl;    a.close();    return 0;}
3

 

c++學習,實驗七

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.