C++Introduction to C++Learn C++Syntax

Easily Learn About Using Input And Output In C++ Programming

In general a developed applications, during it’s runtime, it do 3 actions; it gets inputs, do some logical algorithms and puts you outputs. If you read about Structure of C++ Programming Language, it is good to learn how input and output functions are used.

How do I use Outputs in C++?

In C++, cout object function is used with the << operator, direction of arrows shows the output and anything on the right side of this operator goes as an output. In C++ you must use with std namespace like std::cout. In C++ :: operator is used to refer members of a class or namespace, Here std is standard library which has many functions including input and output object functions. See example below,

Or you can use std as a namespace at the beginning and you don’t need to type std:: before using all of it’s objects. See example below;

Each cout object adds to previous input. You can use many of them, like this;

In this example output, all cout lines will be combined in one line and the output will be like this;

this example is same with;

You can write each of them in one line by using << operator. See this example, it has same output as above too;

This method is easy to output variables. You can output texts and variables together as below,

So, how we can start from the next line, like when you press enter key. Here we use ‘\n’ character at the end or inside the string at the end, We can use endl which shows end of line too. All are same mostly \n is used, because endl See examples below

How do I use Inputs in C++?

In C++, cin object function is used with the >>  operator, direction of arrows shows the output is the variable and anything on the right side of this operator is input. In C++, if you don’t use namespace you must use with it’s std class like std::cout. In C++ :: is used to refer members of a class, Here std is namespace which has input and output object functions. See example below,

Or you can use std as a namespace at the beginning and you don’t need to type std:: before using all of it’s objects as given before. See example below;

This last example is also good to summarize all output and input mechanism in C++.

Head over and download Dev-C++ for modern C++ development on Windows.

Oh hi there 👋
It’s nice to meet you.

Sign up to receive awesome C++ content in your inbox, every day.

We don’t spam! Read our privacy policy for more info.


Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial

Free C++Builder Community Edition

About author

Dr. Yilmaz Yoru has 35+ years of coding with more than 30+ programming languages, mostly C++ on Windows, Android, Mac-OS, iOS, Linux, and some other operating systems. He graduated and received his MSc and PhD degrees from the Department of Mechanical Engineering of Eskisehir Osmangazi University. He is the founder and CEO of ESENJA LLC Company. His interests are Programming, Thermodynamics, Fluid Mechanics, Artificial Intelligence, 2D & 3D Designs, and high-end innovations.
Related posts
C++C++11C++14C++17C++20Introduction to C++Learn C++

Learn Copy Constructors in C++ Classes

C++C++11C++14C++17Introduction to C++Learn C++Syntax

Learn How To Use Types Of Destructors In C++?

C++C++11C++14Learn C++Syntax

How To Convert u32string To A wstring In C++

C++C++11C++14C++17C++20Introduction to C++Learn C++

How To Learn The Move Constructors In Modern C++?