Site icon TestingDocs.com

C++ Basic Input/Output

Introduction

In this post, we will discuss C++ Basic input /output statements. The iostream library provides the objects for doing input and output. cout is the output stream object for output and the << operator. cin is the input stream object for doing the input and the operator >>

Include

In order to use the objects we need to include

#include<iostream>

If you omit the include statement, you will get errors.

‘cout’ was not declared in this scope
‘cin’ was not declared in this scope

C++ Input

https://www.testingdocs.com/c-input-statement/

C++ Output

https://www.testingdocs.com/c-output-statement/

Detect Errors

cin has some helpful functions to prevent the input from the user. For example, cin.fail() The fail function will return true if there are errors in the input stream.

if(!cin) {

// proceed with the code

}

The example C++ program with both input and output statements :

https://www.testingdocs.com/c-program-to-compute-area-circumference-of-a-circle/

C++ Tutorials

C++ Tutorials on this website:

https://www.testingdocs.com/c-coding-tutorials/

For more information on the current ISO C++ standard

https://isocpp.org/std/the-standard

Exit mobile version