cout 是 C 中用於在控制台上輸出資料的物件。其輸出方法包括:使用插入運算元 (<<) 輸出資料。呼叫成員函數,如 put() 輸出單一字符,write() 輸出字串或數組,flush() 強制刷新輸出緩衝區。
C 中 cout 的使用方法
什麼是 cout?
cout 是 C 標準函式庫中的一個對象,用於在控制台上輸出資料。
使用方法
使用cout 輸出資料有兩種主要方法:
使用插入運算子(<) 將資料輸出到cout 流中。例如:
cout << "Hello, world!" << endl; // 输出 "Hello, world!" 字符串
cout 物件也提供了幾個成員函數用於輸出數據,例如:
範例
#以下程式碼示範了cout 物件的使用:
#include <iostream> using namespace std; int main() { cout << "Enter your name: "; string name; getline(cin, name); cout << "Hello, " << name << "!" << endl; return 0; }
注意:
以上是c語言中cout怎麼用的詳細內容。更多資訊請關注PHP中文網其他相關文章!