| printf | cout | 說明 |
|---|---|---|
printf("%c", ch); | cout << ch; | 字符直接輸出 |
printf("%d", num); | cout << num; | 整數 |
printf("%f", f); | cout << f; | 浮點數(默認 6 位小數) |
printf("%.2f", f); | cout << fixed << setprecision(2) << f; | 需 <iomanip> |
printf("%s", str); | cout << str; | C 字符串/string |
// 原代碼
printf("%c", ht[f].data);
// 轉換後
cout << ht[f].data;
operator<< 支持自定義類型cout << a << b << c;C++ 現代編程推薦優先使用 iostream (cout/cin),printf 留給 C 兼容/極致性能/特定格式化場景。