{"id":65,"date":"2026-05-19T14:56:22","date_gmt":"2026-05-19T14:56:22","guid":{"rendered":"https:\/\/gigz.pk\/cpp\/?post_type=lesson&#038;p=65"},"modified":"2026-05-22T06:26:25","modified_gmt":"2026-05-22T06:26:25","slug":"input-and-output","status":"publish","type":"lesson","link":"https:\/\/gigz.pk\/cpp\/?lesson=input-and-output","title":{"rendered":"Input and Output"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Input and output are basic concepts in C++ programming. They allow a program to take data from the user and display results on the screen.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is Input?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Input means taking data from the user or another source into the program.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Entering name<\/li>\n\n\n\n<li>Entering age<\/li>\n\n\n\n<li>Entering numbers<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">What is Output?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Output means displaying information from the program to the user.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Showing result<\/li>\n\n\n\n<li>Displaying messages<\/li>\n\n\n\n<li>Printing calculations<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Input and Output Library<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">C++ uses the <code>&lt;iostream&gt;<\/code> library for input and output operations.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;iostream&gt;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Output Using cout<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><code>cout<\/code> is used to display output on the screen.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Syntax<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>cout &lt;&lt; value;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Example<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;iostream&gt;<br>using namespace std;<br><br>int main() {<br>    cout &lt;&lt; \"Welcome to C++\";<br><br>    return 0;<br>}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Output<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>Welcome to C++<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Input Using cin<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><code>cin<\/code> is used to take input from the user.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Syntax<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>cin &gt;&gt; variable;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Example<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;iostream&gt;<br>using namespace std;<br><br>int main() {<br>    int age;<br><br>    cin &gt;&gt; age;<br><br>    cout &lt;&lt; age;<br><br>    return 0;<br>}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Example with Message<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;iostream&gt;<br>using namespace std;<br><br>int main() {<br>    string name;<br><br>    cout &lt;&lt; \"Enter your name: \";<br>    cin &gt;&gt; name;<br><br>    cout &lt;&lt; \"Hello \" &lt;&lt; name;<br><br>    return 0;<br>}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Output Example<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>Enter your name: Ali<br>Hello Ali<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Using endl<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><code>endl<\/code> is used to move output to the next line.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cout &lt;&lt; \"Line 1\" &lt;&lt; endl;<br>cout &lt;&lt; \"Line 2\";<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Multiple Inputs<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>int a, b;<br><br>cin &gt;&gt; a &gt;&gt; b;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Example Program<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;iostream&gt;<br>using namespace std;<br><br>int main() {<br>    int num1, num2;<br><br>    cout &lt;&lt; \"Enter two numbers: \";<br>    cin &gt;&gt; num1 &gt;&gt; num2;<br><br>    cout &lt;&lt; \"Sum: \" &lt;&lt; num1 + num2;<br><br>    return 0;<br>}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Output Example<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>Enter two numbers: 5 3<br>Sum: 8<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Important Points<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>cin<\/code> is used for input<\/li>\n\n\n\n<li><code>cout<\/code> is used for output<\/li>\n\n\n\n<li><code>&lt;&lt;<\/code> is insertion operator<\/li>\n\n\n\n<li><code>&gt;&gt;<\/code> is extraction operator<\/li>\n\n\n\n<li><code>endl<\/code> creates a new line<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Why Input and Output are Important<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">They are important because they:<\/p>\n\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1779431108674\"><strong class=\"schema-faq-question\"><\/strong> <p class=\"schema-faq-answer\"><\/p> <\/div> <\/div>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Allow user interaction<\/li>\n\n\n\n<li>Make programs dynamic<\/li>\n\n\n\n<li>Display results clearly<\/li>\n\n\n\n<li>Help process user data<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Input and output operations are essential in C++ programming. Using <code>cin<\/code> and <code>cout<\/code>, programs can interact with users by taking input and displaying meaningful results. Understanding these concepts is important for building interactive applications.<\/p>\n\n\n<div class=\"yoast-breadcrumbs\"><span><span><a href=\"https:\/\/gigz.pk\/cpp\">Home<\/a><\/span> \u00bb <span class=\"breadcrumb_last\" aria-current=\"page\">C++ Fundamentals (Beginner Level) > Basics of Programming > Input and Output<\/span><\/span><\/div>","protected":false},"menu_order":9,"template":"","class_list":["post-65","lesson","type-lesson","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Input and Output - Learn C++Language with GiGz.PK<\/title>\n<meta name=\"description\" content=\"Learn C++ input and output using cin, cout, endl, and iostream with beginner-friendly examples and syntax.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/gigz.pk\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Input and Output - Learn C++Language with GiGz.PK\" \/>\n<meta property=\"og:description\" content=\"Learn C++ input and output using cin, cout, endl, and iostream with beginner-friendly examples and syntax.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/gigz.pk\/\" \/>\n<meta property=\"og:site_name\" content=\"Learn C++Language with GiGz.PK\" \/>\n<meta property=\"article:modified_time\" content=\"2026-05-22T06:26:25+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":[\"WebPage\",\"FAQPage\"],\"@id\":\"https:\\\/\\\/gigz.pk\\\/cpp\\\/?lesson=input-and-output\",\"url\":\"https:\\\/\\\/gigz.pk\\\/\",\"name\":\"Input and Output - Learn C++Language with GiGz.PK\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/cpp\\\/#website\"},\"datePublished\":\"2026-05-19T14:56:22+00:00\",\"dateModified\":\"2026-05-22T06:26:25+00:00\",\"description\":\"Learn C++ input and output using cin, cout, endl, and iostream with beginner-friendly examples and syntax.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/gigz.pk\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/gigz.pk\\\/cpp\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"C++ Fundamentals (Beginner Level) > Basics of Programming > Input and Output\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/cpp\\\/#website\",\"url\":\"https:\\\/\\\/gigz.pk\\\/cpp\\\/\",\"name\":\"Learn C++Language with GiGz.PK\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/gigz.pk\\\/cpp\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Input and Output - Learn C++Language with GiGz.PK","description":"Learn C++ input and output using cin, cout, endl, and iostream with beginner-friendly examples and syntax.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/gigz.pk\/","og_locale":"en_US","og_type":"article","og_title":"Input and Output - Learn C++Language with GiGz.PK","og_description":"Learn C++ input and output using cin, cout, endl, and iostream with beginner-friendly examples and syntax.","og_url":"https:\/\/gigz.pk\/","og_site_name":"Learn C++Language with GiGz.PK","article_modified_time":"2026-05-22T06:26:25+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["WebPage","FAQPage"],"@id":"https:\/\/gigz.pk\/cpp\/?lesson=input-and-output","url":"https:\/\/gigz.pk\/","name":"Input and Output - Learn C++Language with GiGz.PK","isPartOf":{"@id":"https:\/\/gigz.pk\/cpp\/#website"},"datePublished":"2026-05-19T14:56:22+00:00","dateModified":"2026-05-22T06:26:25+00:00","description":"Learn C++ input and output using cin, cout, endl, and iostream with beginner-friendly examples and syntax.","breadcrumb":{"@id":"https:\/\/gigz.pk\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/gigz.pk\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/gigz.pk\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/gigz.pk\/cpp"},{"@type":"ListItem","position":2,"name":"C++ Fundamentals (Beginner Level) > Basics of Programming > Input and Output"}]},{"@type":"WebSite","@id":"https:\/\/gigz.pk\/cpp\/#website","url":"https:\/\/gigz.pk\/cpp\/","name":"Learn C++Language with GiGz.PK","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/gigz.pk\/cpp\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/gigz.pk\/cpp\/index.php?rest_route=\/wp\/v2\/lesson\/65","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gigz.pk\/cpp\/index.php?rest_route=\/wp\/v2\/lesson"}],"about":[{"href":"https:\/\/gigz.pk\/cpp\/index.php?rest_route=\/wp\/v2\/types\/lesson"}],"wp:attachment":[{"href":"https:\/\/gigz.pk\/cpp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=65"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}