Chaining Multiple String Literals – CSKC
Sign In

Search

Code Learning #CPP#7573    siteicon   siteicon  

Chaining Multiple String Literals

This program prints the sentence “My country is wonderful” using multiple strings combined with the stream insertion operator (<<) in C++.

Learning Objectives

To understand how C++ outputs text using std::cout and how multiple strings can be combined using the stream insertion operator.

Program Approach

Include the iostream library, start execution from main(), use std::cout with multiple << operators to print the strings sequentially, and use std::endl to move to the next line.

Source Code

TC++ #7573

 

Source Code

×

Ask AI About This Code

Default Prompt that is passed along with the code is given below, You can write your own prompt if you so desire.



×

Test CPP

Code Understanding

#include <iostream>
Includes the iostream header file which provides input-output facilities like cout.

int main()
Defines the main() function where program execution begins.

std::cout<< “My country “
Prints the text “My country ” to the output screen.

<<“is “
Adds the string “is ” to the same output stream.

<<“wonderful”
Adds the string “wonderful” to the output stream.

<<std::endl;
Moves the cursor to the next line after printing.

return 0;
Terminates the program and returns 0 to the operating system indicating successful execution.

Notes

C++ allows chaining of multiple << operators to print several strings in a single statement.
The compiler treats adjacent insertion operations as a continuous output stream.
Proper spacing inside the strings determines the final printed format.

Common Errors

Forgetting std:: before cout when using <iostream>.
Missing semicolon at the end of the cout statement.
Removing spaces inside strings may produce output like “My countryiswonderful”.
Using <iostream> instead of <iostream.h> when compiling in Turbo C++.


Suggested Filename(s): multiple_string_output.cpp



Share

Created: 28-Feb-2026 19:41 | Updated: 7-Mar-2026 17:39|