In this article, we are going to learn how to display text on the screen using C++. I am using a Visual Studio 2017 Community Edition. You can download it for free on this link Visual Studio 2017 Community Edition.
After installing,
Step 1: Open Visual Studio 2017 Community Edition
Step 2: Click File -> New -> Project
Step 3: Select Visual C++
Step 4: Under Visual C++, Select Windows Desktop
Step 5: Select Windows Console Application
Step 6: Write the name of the Project and click OK.
After clicking OK, this will be showing on your screen with the following codes.
Press Control + F5 to see the output that we coded in Visual Studio
Example: We want to write a program displaying “Hello” on the first line, and “World” on the second line.
To do that, change your code into
#include "pch.h" #include int main() { std::cout << "Hello" << std::endl; std::cout << "World!"; }
Press Control + F5. Below is the output.It breaks the line because of the std::endl;
std::endl; —means the next cout should be on the next line
cout —is what are you going to display in the screen
Testing: Without coding std::end; after “Hello”.
#include "pch.h" #include int main() { std::cout << "Hello "; std::cout << "World!"; }
Press Control + F5. And below is the output.