Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • C++ Data Types
  • C++ Input/Output
  • C++ Arrays
  • C++ Pointers
  • C++ OOPs
  • C++ STL
  • C++ Interview Questions
  • C++ Programs
  • C++ Cheatsheet
  • C++ MCQ
  • C++ Projects
  • C++ Exception Handling
  • C++ Memory Management
Open In App
Next Article:
Output in C++
Next article icon

Output in C++

Last Updated : 14 Apr, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report

In this article, we will discuss the very basic and most common I/O operations required for C++ programming. C++ runs on lots of platforms like Windows, Linux, Unix, Mac, etc. This is the most basic method for handling output in C++.
The cout is used very often for printing outputs, i.e., on the monitor. The predefined object cout is an instance of iostream class. For formatted output operations, cout is used together with the insertion operator, which is written as “<<” (i.e., two “less than” signs).  

Program 1:
Below is the C++ program to demonstrate the use of cout object:

C++
// C++ program to demonstrate cout #include <iostream> using namespace std;  // Driver Code int main() {     // Used to display the output     // to the standard output device     cout << "GeeksforGeeks!";      return 0; } 

Output
GeeksforGeeks!

Time Complexity: O(1)
Auxiliary Space: O(1)

Note:

  • #include is known as a preprocessor directive, which is used to load files.
  • iostream is a header file that contains functions for input/output operations (cin and cout).

Program 2:
Below is the C++ program to demonstrate a manipulator that can be used with the cout object:

C++
// C++ program to demonstrate the // endl manipulator #include <iostream> using namespace std;  // Driver Code int main() {      // Stores the data in a     // variable str     char str[] = "Geeksforgeeks";      // Print the output     cout << " A computer science portal"          << " for geeks - " << str;      return 0; } 

Output
 A computer science portal for geeks - Geeksforgeeks

Time Complexity: O(1)
Auxiliary Space: O(1)

Program 3:

In this example, the user will be asked for his/her city name, when the user enters his/her city it will store the city name in the name variable. After that, the console will print the output string. Below is the program for the same:

C++
// C++ program to illustrate the // above concept #include <iostream> using namespace std;  // Driver Code int main() {     // Name variable can store     // upto 30 character     char name[30];      // Print the output(asking user     // to enter city name)     cout << "Please enter your city name: ";      // Take input from user and store     // in name variable     cin >> name;      // Print output string including     // user input data     cout << "Your city is: "          << name << endl;      return 0; } 

Input: Mumbai

Output: Mumbai

Time Complexity: O(1)
Auxiliary Space: O(1)


Next Article
Output in C++

S

skrg141
Improve
Article Tags :
  • C++ Programs
  • C++
  • cpp-input-output
  • Input Output Systems
Practice Tags :
  • CPP

Similar Reads

    Input in C++
    The cin object in C++ is used to accept the input from the standard input device i.e., keyboard. it is the instance of the class istream. It is associated with the standard C input stream stdin. The extraction operator(>>) is used along with the object cin for reading inputs. The extraction op
    2 min read
    cin in C++
    In C++, cin is an object of istream class that is used to accept the input from the standard input stream i.e. stdin which is by default associated with keyboard. The extraction operator (>>) is used along with cin to extract the data from the object and insert it to the given variable.Let's t
    4 min read
    How to Right Justify Output in C++?
    In C++, the outputs produced by the program are by default to the left of the screen. In this article, we will learn how to right justify the output in C++. Example: Input:float x= 123.45float y= 6.7899Output: 123.45 6.7899 // justified on the console’s right side.Right Justifying the Output in C++T
    2 min read
    Unformatted input/output operations In C++
    In this article, we will discuss the unformatted Input/Output operations In C++. Using objects cin and cout for the input and the output of data of various types is possible because of overloading of operator >> and << to recognize all the basic C++ types. The operator >> is overlo
    4 min read
    Structure of C++ Program
    The C++ program is written using a specific template structure. The structure of the program written in C++ language is as follows: Documentation Section:This section comes first and is used to document the logic of the program that the programmer going to code.It can be also used to write for purpo
    5 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences