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.

Related posts
C++Learn C++Videos

Learn C++ With Design Patterns For Handling/Reporting Errors In C++: Parallel Algorithms And Executors by Mark Hoemmen (CPPCon 2020) Videos

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

Learn To Use Break And Continue In Loops With C++

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

Learn To Define And Use Arrays In C++

C++Learn C++Videos

Learn C++ With Back to Basics: Design Pattern by Mike Shah (CPPCon 2020) Video

en_USEnglish