<< Chapter < Page Chapter >> Page >
Phần này trình bày về các dạng nhập/xuất trong lập trình hướng đối tượng

DẪN NHẬP

Các thư viện chuẩn C++ cung cấp một tập hợp các khả năng nhập/xuất rộng lớn. Trong chương này chúng ta tìm hiểu một phạm vi của các khả năng đủ để phần lớn các thao tác nhập xuất.

Phần lớn các đặc tính nhập xuất mô tả ở đây theo hướng đối tượng. Kiểu này của nhập/xuất thi hành việc sử dụng các đặc tính khác của C++ như các tham chiếu, đa năng hóa hàm và đa năng hóa toán tử.

Như chúng ta sẽ thấy, C++ sử dụng nhập/xuất kiểu an toàn (type safe). Mỗi thao tác nhập/xuất được thực hiện một cách tự động theo lối nhạy cảm về kiểu dữ liệu. Mỗi thao tác nhập xuất có được định nghĩa thích hợp để xử lý một kiểu dữ liệu cụ thể thì hàm đó được gọi để xử lý kiểu dữ liệu đó. Nếu không có đối sánh giữa kiểu của dữ liệu hiện tại và một hàm cho việc xử lý kiểu dữ liệu đó, một chỉ dẫn lỗi biên dịch được thiết lập. Vì thế dữ liệu không thích hợp không thể "lách" qua hệ thống.

Các người dùng có thể chỉ định nhập/xuất của các kiểu dữ liệu do người dùng định nghĩa cũng như các kiểu dữ liệu chuẩn. Tính mở rộng này là một trong các đặc tính quan trọng của C++.

Các dòng(streams)

Nhập/xuất C++ xảy ra trong các dòng của các byte. Một dòng đơn giản là một dãy tuần tự các byte. Trong các thao tác nhập, các byte chảy từ thiết bị (chẳng hạn: một bàn phím, một ổ đĩa, một kết nối mạng) tới bộ nhớ chính. Trong các thao tác xuất, các byte chảy từ bộ nhớ chính tới một thiết bị (chẳng hạn: một màn hình, một máy in, một ổ đĩa, một kết nối mạng).

Ưùng dụng liên kết với các byte. Các byte có thể biểu diễn các ký tự ASCII, bên trong định dạng dữ liệu thô, các ảnh đồ họa, tiếng nói số, hình ảnh số hoặc bất cứ loại thông tin một ứng dụng có thể đòi hỏi.

Công việc của các cơ chế hệ thống nhập/xuất là di chuyển các byte từ các thiết bị tới bộ nhớ và ngược lại theo lối chắc và đáng tin cậy. Như thế các di chuyển thường bao gồm sự di chuyển cơ học như sự quay của một đĩa hoặc một băng từ, hoặc nhấn phím tại một bàn phím. Thời gian các di chuyển này thông thường khổng lồ so với thời gian bộ xử lý thao tác dự liệu nội tại. Vì thế, các thao tác nhập/xuất đòi hỏi có kế hoạch cẩn thận và điều chỉnh để bảo đảm sự thi hành tối đa.

C++ cung cấp cả hai khả năng nhập/xuất "mức thấp" (low-level) và "mức cao" (high-level). Các khả năng nhập/xuất mức thấp (nghĩa là nhập/xuất không định dạng) chỉ định cụ thể số byte nào đó phải được di chuyển hoàn toàn từ thiết bị tới bộ nhớ hoặc từ bộ nhớ tới thiết bị. Trong các di chuyển như thế, byte riêng rẽ là mục cần quan tâm. Vì thế các khả năng mức thấp cung cấp tốc độ cao, các di chuyển dung lượng cao, nhưng các khả năng này không phải là tiện lợi lắm cho lập trình viên.

Các lập trình viên ưu thích quan điểm nhập/xuất mức cao, nghĩa là nhập/xuất có định dạng, trong đó các byte được nhóm thành các đơn vị có ý nghĩa như các số nguyên, các số chấm động, các ký tự, các chuỗi và các kiểu do người dùng định nghĩa.

Các file header của thư viện iostream

Thư viện iostream của C++ cung cấp hàng trăm khả năng của nhập/xuất. Một vài tập tin header chứa các phần của giao diện thư viện.

Questions & Answers

how does Neisseria cause meningitis
Nyibol Reply
what is microbiologist
Muhammad Reply
what is errata
Muhammad
is the branch of biology that deals with the study of microorganisms.
Ntefuni Reply
What is microbiology
Mercy Reply
studies of microbes
Louisiaste
when we takee the specimen which lumbar,spin,
Ziyad Reply
How bacteria create energy to survive?
Muhamad Reply
Bacteria doesn't produce energy they are dependent upon their substrate in case of lack of nutrients they are able to make spores which helps them to sustain in harsh environments
_Adnan
But not all bacteria make spores, l mean Eukaryotic cells have Mitochondria which acts as powerhouse for them, since bacteria don't have it, what is the substitution for it?
Muhamad
they make spores
Louisiaste
what is sporadic nd endemic, epidemic
Aminu Reply
the significance of food webs for disease transmission
Abreham
food webs brings about an infection as an individual depends on number of diseased foods or carriers dully.
Mark
explain assimilatory nitrate reduction
Esinniobiwa Reply
Assimilatory nitrate reduction is a process that occurs in some microorganisms, such as bacteria and archaea, in which nitrate (NO3-) is reduced to nitrite (NO2-), and then further reduced to ammonia (NH3).
Elkana
This process is called assimilatory nitrate reduction because the nitrogen that is produced is incorporated in the cells of microorganisms where it can be used in the synthesis of amino acids and other nitrogen products
Elkana
Examples of thermophilic organisms
Shu Reply
Give Examples of thermophilic organisms
Shu
advantages of normal Flora to the host
Micheal Reply
Prevent foreign microbes to the host
Abubakar
they provide healthier benefits to their hosts
ayesha
They are friends to host only when Host immune system is strong and become enemies when the host immune system is weakened . very bad relationship!
Mark
what is cell
faisal Reply
cell is the smallest unit of life
Fauziya
cell is the smallest unit of life
Akanni
ok
Innocent
cell is the structural and functional unit of life
Hasan
is the fundamental units of Life
Musa
what are emergency diseases
Micheal Reply
There are nothing like emergency disease but there are some common medical emergency which can occur simultaneously like Bleeding,heart attack,Breathing difficulties,severe pain heart stock.Hope you will get my point .Have a nice day ❣️
_Adnan
define infection ,prevention and control
Innocent
I think infection prevention and control is the avoidance of all things we do that gives out break of infections and promotion of health practices that promote life
Lubega
Heyy Lubega hussein where are u from?
_Adnan
en français
Adama
which site have a normal flora
ESTHER Reply
Many sites of the body have it Skin Nasal cavity Oral cavity Gastro intestinal tract
Safaa
skin
Asiina
skin,Oral,Nasal,GIt
Sadik
How can Commensal can Bacteria change into pathogen?
Sadik
How can Commensal Bacteria change into pathogen?
Sadik
all
Tesfaye
by fussion
Asiina
what are the advantages of normal Flora to the host
Micheal
what are the ways of control and prevention of nosocomial infection in the hospital
Micheal
what is inflammation
Shelly Reply
part of a tissue or an organ being wounded or bruised.
Wilfred
what term is used to name and classify microorganisms?
Micheal Reply
Binomial nomenclature
adeolu
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Lập trình hướng đối tượng. OpenStax CNX. Jul 29, 2009 Download for free at http://cnx.org/content/col10794/1.1
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Lập trình hướng đối tượng' conversation and receive update notifications?

Ask