c++使用setw(int n)來控制他後面的變數的輸出佔多少個位置。預設是右對齊。
例子:
c語言是在輸出個數符前面加上數字或者小數點來實現的額,例如printf("%8d",n);這樣後面的數n也是佔8個位置,預設右對齊,#include using namespace std;
#include using std::setw;
/*setw(int n)用來控制輸出間隔。
cout<<'s'<
element value
0 100
1 101
2 102
3 103
4 104
5 105
6 106
7 107
8 108
9 109
------------------------------
9 109
------------------------------
9######109##########
------------------------------
######9##########109
process returned 0 (0x0) execution time : 0.097 s
press any key to continue.
如果想要左對齊只要在百分號後面加乙個減號就行了:printf("%-8d",n);
c語言例子:
結果:#includeint main ()
printf("%s%13s\n","element","value");
// 輸出陣列中每個元素的值
int j;
for ( j = 0; j < 10; j++ )
printf("------------------------------\n");
printf("%-7d%-13d\n",9,9);
printf("------------------------------\n");
return 0;
}
element value
0 100
1 101
2 102
3 103
4 104
5 105
6 106
7 107
8 108
9 109
------------------------------
9 9
------------------------------
process returned 0 (0x0) execution time : 0.152 s
press any key to continue.
C C 控制台輸入輸出
c 1.輸入 1 readline string input console.readline 讀取一串字元,直到使用者按下回車。string input while input console.readline null 若要讀取一行多個數字,可以使用如下方法 string str str inp...
C C 輸出格式控制符
c c 格式控制符 一 型別 型別字元用以表示輸出資料的型別,其格式符和意義如下表所示 格式字元意義d 以十進位制形式輸出帶符號整數 正數不輸出符號 o以八進位制形式輸出無符號整數 不輸出字首0 x,x以十六進製制形式輸出無符號整數 不輸出字首ox u以十進位制形式輸出無符號整數 f以小數形式輸出單...
時間間隔輸出函式 python3
因為專案需要輸出指定時間間隔和間隔內模組上報的次數,為了避免每次用計算器算,所以自己封裝了乙個函式,以供自己使用 import time deftime unix old time 將格式為 2020 9 18 17 50 00 的時間轉成unix表示的時間戳 data sj time.strpti...