跳到主要內容

程式設計-C語言 / OLD / 訊二甲( 江 ) / 上學期 / 1119-cout 格式化輸出

 

C++ cout格式化輸出(輸出格式)完全攻略

字串和 I/O 格式化 (現代 C++)

 

800

 

 
using namespace std;
int main(int argc, char** argv) {
 
cout << hex << 59 << "," << 62 << endl;
int n = 141;
    //1) 分別以十六進位制、十進位制、八進位制先後輸出 n
    cout << "1)" << hex << n << " " << dec << n << " " << oct << n << "\n";  //endl;
    double x = 1234567.89, y = 12.3456;
    
    //2)保留5位有效數位
    cout << "2)" << setprecision(5) << x << " " << y << " " << endl;
    
    //3)保留小數點後面5位
    cout << "3)" << fixed << setprecision(5) << x << " " << y << endl;
    
    //4)科學計數法輸出,且保留小數點後面5位
    cout << "4)" << scientific << setprecision(5) << x << " " << y << endl;
    return 0;
}

 

 

時間類別單位標題發佈點閱
跳至網頁頂部