C++ 流類結構
在 C++ 流 中指的是程式執行緒和 I/O 之間傳輸的字元流。
C++ 中的流類用於對檔案和 I/O 裝置進行輸入和輸出操作。這些類具有特定的功能來處理程式的輸入和輸出。
iostream.h 庫 包含了 C++ 程式語言 中的所有流類。
讓我們看看它們的層次結構並瞭解它們。

現在,讓我們學習一下iostream庫中的類。
ios 類 - 這個類是所有流類的基類。流可以是輸入流或輸出流。此類定義了獨立於類模板定義方式的成員。
istream 類 - istream 類處理 C++ 程式語言中的輸入流。這些輸入流物件用於讀取和解釋輸入作為一系列字元。cin 處理輸入。
ostream 類 - ostream 類處理 C++ 程式語言中的輸出流。這些輸出流物件用於將資料作為一系列字元寫入螢幕。cout 和 puts 處理 C++ 程式語言中的輸出流。
示例
輸出流
COUT
#include <iostream>
using namespace std;
int main(){
cout<<"This output is printed on screen";
}輸出
This output is printed on screen
PUTS
#include <iostream>
using namespace std;
int main(){
puts("This output is printed using puts");
}輸出
This output is printed using puts
輸入流
CIN
#include <iostream>
using namespace std;
int main(){
int no;
cout<<"Enter a number ";
cin>>no;
cout<<"Number entered using cin is "<輸出
Enter a number 3453 Number entered using cin is 3453
gets
#include <iostream>
using namespace std;
int main(){
char ch[10];
puts("Enter a character array");
gets(ch);
puts("The character array entered using gets is : ");
puts(ch);
}輸出
Enter a character array thdgf The character array entered using gets is : thdgf
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP