The C++ programming language does not define any statement to perform input and output operations. Instead, C++ has a separate input/output library that is part of the C++ standard library that provides primary input/output and many other facilities.
For the purpose of input and output, you will use the iostream (input-output stream) library which is a part of the C++ standard library. You need to include iostream header file on top of any C++ code file to use the properties define in this library.
#include<iostream> //header file int main() { //include the rest of your code here }
Note: A stream is a sequence of characters read from or written to an Input/Output device.
- When the direction of the flow of characters is from the device to the main memory then this process is called input.
- When the direction of the flow of characters is from the main memory to the device then this process is called output.
There are basically four standard objects present inside the iostream library and these are:
Objects | Uses |
---|---|
std::cin (pronounced see-in) | Standard input |
std::cout (pronounced see-out) | Standard output |
std::cerr (pronounced see-err) | Standard error |
std::clog (pronounced see-log) | General information |
#include<iostream> //header file int main() { std::cout<<"Hello AlgoLesson"; //printing Hello AlgoLesson on consolestd::cout<<4; //printing 4return 0; }
Hello AlgoLesson4
#include<iostream> //header file int main() { int x; //variable to hold input std::cout<<"Enter the value of x: "; std::cin>> x; //getting input from keyboard and store in x std::cout<<"Value of x: " << x ; return 0; }
Enter the value of x: 7
Value of x: 7
#include<iostream> //header file int main() { std::cerr <<"This is an error message"; return 0; }
This is an error message
#include<iostream> //header file int main() { std::clog <<"This is an error message log"; return 0; }
This is an error message log
#include<iostream> //header file int main() { std::cout <<"Welcome to AlgoLesson" << std::endl; std::cout <<"You are learning C++"; return 0; }
Welcome to AlgoLesson
You are learning C++
No comments:
Post a Comment