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.

close

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.

About author

33+ years of coding with more than 30+ programming languages, mostly C++ on Windows, Android, Mac-OS, iOS, Linux and some other operating systems. Dr. Yilmaz Yoru was born in 1974, Eskisehir-Turkey. He graduated from the department of Mechanical Engineering of Eskisehir Osmangazi University in 1997. One year later he started to work in the same university as an assistant. He received his MSc and PhD degrees from the same department of the same university. He has married and he is a father of a son. Some of his interests are Programming, Thermodynamics, Fluid Mechanics and Artificial Intelligence. He also likes the graphical 2D & 3D design and high-end innovations.
Related posts
C++C++11C++14C++17Introduction to C++Learn C++

This Is How To Get A Substring of a Wide String in C++

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

How To Access Individual Character Elements Of A C++ String

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

The Right Way To Access Character Elements Of A Wide String

C++Language FeatureLearn C++

You NEED to Learn To Use JSON (JavaScript Object Notation)

en_USEnglish