Input and Output in C++

📘 C++ 👁 52 views 📅 Dec 22, 2025
⏱ Estimated reading time: 2 min

Input and output operations allow interaction between the user and the program.


1. Input in C++

C++ uses the cin object to take input from the user.

Syntax

cin >> variable;

Example

int age; cin >> age;
  • >> is called the extraction operator

  • Takes input from the keyboard


2. Output in C++

C++ uses the cout object to display output on the screen.

Syntax

cout << variable>

Example

cout << age>
  • << is called the insertion operator

  • Displays output on the screen


3. Header File Required

To use cin and cout, include:

#include using namespace std;

4. Displaying Text and Variables

cout << "Age: " << age>
  • Multiple values can be displayed using <<


5. Taking Multiple Inputs

int a, b; cin >> a >> b;

6. New Line in Output

Using endl:

cout << "Hello" << endl>

Using \n:

cout << "Hello\n";

7. Complete Example Program

#include using namespace std; int main() { int x, y; cin >> x >> y; cout << "Sum = " << x>return 0; }

8. Input and Output with Strings

string name; cin >> name; cout << name>

Note: cin reads input only until a space.


Key Points

  • cin is used for input

  • cout is used for output

  • >> and << are stream operators

  • endl moves the cursor to a new line


Conclusion

Input and output operations are essential for making C++ programs interactive and user-friendly.


🔒 Some advanced sections are available for Registered Members
Register Now

Share this Post


← Back to Tutorials

Popular Competitive Exam Quizzes

🤖 AI Quizer Assistant

📝 Quiz
📚 Categories
🏆 Leaderboard
📊 My Score
❓ Help
👋 Hi! I'm your AI quiz assistant for Quizer.in!

I can help you with:
• 📝 Finding quizzes
• 🏆 Checking leaderboard
• 📊 Your performance stats

Type 'help' to get started! 🚀
AI is thinking...