mirror of
https://github.com/kamranahmedse/developer-roadmap.git
synced 2026-10-28 02:43:08 +08:00
Co-authored-by: kamranahmedse <4921183+kamranahmedse@users.noreply.github.com>
1.6 KiB
1.6 KiB
iostream
iostream is a header in the C++ Standard Library that provides functionality for basic input and output (I/O) operations. The I/O streams facilitate communication between your program and various sources, such as the console, files, or other programs.
iostream includes the following classes:
istream: for input operations from an input source.ostream: for output operations to an output target.iostream: a combination ofistreamandostreamfor both input and output operations.
These classes inherit from base classes ios and ios_base.
Additionally, iostream defines several objects that are instances of these classes and represent the standard input and output streams:
cin: anistreamobject to read from the standard input, typically corresponding to the keyboard.cout: anostreamobject to write to the standard output, typically the console.cerr: anostreamobject to write to the standard error output, typically used for displaying error messages.clog: anostreamobject, similar tocerr, but its output can be buffered.
Here are some code examples on using iostream for input and output operations:
#include <iostream>
int main() {
int a;
std::cout << "Enter a number: ";
std::cin >> a;
std::cout << "You entered: " << a << '\n';
return 0;
}
#include <iostream>
int main() {
std::cerr << "An error occurred.\n";
std::clog << "Logging information.\n";
return 0;
}
Remember to include the iostream header when using these features:
#include <iostream>