學習筆記 setfill和setw

2021-07-03 16:03:12 字數 1069 閱讀 8531

time.h

#ifndef time_h

#define time_h

//time class definition

class time

;time.cpp

#include

#include

#include "time.h"

using

namespace

std;

time::time()

void time::settime(int h, int m, int s)

void time::printtuniversal()

void time::printstandard()

main.cpp

#include

#include"time.h">

using

namespace

std;

int main()

結果

the initial universal time is 00:00:00

the initial standard time is 12:00:00

universal time after settime is 13:27:06

standard time after settime is 1:27:06 pm

after attempting invalid settings:

universal time: 00:00:00

standard time: 12:00:00 am

通過結果可以看出,在printuniversal和printstandard中,使用setfill設定填充字元為『0』,因此當minute為2時,將會顯示02。若實際輸出填滿了setw指定的域寬,那麼就不會顯示填充字元。

note:一旦setfill指定了填充字元,該字元將應用在後續值的顯示中。也就是說,setfill是乙個「黏性」設定,但setw是乙個「非粘性」設定,其只對緊接著顯示的值起作用。對於粘性設定,當不需要時應恢復,否則可能會出現格式錯誤。

python學習筆記 使用dict和set

python內建了字典 dict的支援,dict全稱dictionary,在其他語言中也稱為map,使用鍵 值 key value 儲存,具有極快的查詢速度。1.定義字典 字典由多個鍵及與其對應值構成的鍵 值對組成,鍵與值之間用 隔開。dict1 建立乙個空字典 dict2 建立字典注意,字典的鍵是...

STL學習筆記7 容器set和multiset

在標頭檔案中定義 namespace std set和multiset都是關聯容器,是有序的集合,集合中包含不可重複的 型別為key的元素。排序通過使用型別為compare的比較函式比較來實現。搜尋,刪除和插入操作具有對數時間複雜度。set和multiset通常都以紅黑樹實現。multiset相對s...

ES6學習筆記 Set和Map

set類似於陣列,但是沒有重複的值,成員是唯一的。set例項有兩個屬性 set.prototype.constructor指向set本身,set.prototype.size返回set例項的成員總數。set例項的方法分為兩大類 操作方法 用於運算元據 和遍歷方法 用於遍歷成員 array.from方...