How to print text in C++?
There is a simple way of printing text in C++. You can use the 'cout' object along with the insertion operator, '>>'. You need to write all the basic lines of C++ code first and inside a curly bracket'{}', write 'cout>>' and then write the text in double quotes (""). Also remember to add the semi-colon at the end of the line.
For example-
#include <iostream>
using namespace std;
int main()
{
cout<<"Hello World!";
return 0;
}
Adding a break between two pieces of text
You can add a break between lines by adding '\n' after every piece of text that has to be printed. For example-
#include <iostream>
using namespace std;
int main()
{
cout<<"Hello World! \n";
cout<<"C++ is fun!";
return 0;
}
Similarly, the number of lines can be increased by adding '\n' characters at the end of the lines.
Adding a horizontal tag
You can add a horizontal tag by writing '\t' at the end of the line like the '\n'. For example;
#include <iostream>
using namespace std;
int main()
{
cout<<"Hello World! \t";
cout<<"C++ is fun!";
return 0;
}
Putting double quotes around a piece of text
You can put double quotes by adding '\"' at the start and the end of the piece of text. For example-
#include <iostream>
using namespace std;
int main()
{
cout<<"His name is \"Jhonny\"";
return 0;
}
That is all for this post. Follow this blog to get more info on coding.
Regards,
Aarav Iyer
References;