Learn C++ with me part 1-4
Part1
let's try simple coding and printout "Hello World" in C++
try this code to printout "Hello World in C++
#include
int main(void) {
std::cout<<"Hello World";
return 0;
}
Syntax: std::cout
The std::cout statement in C++ is a built-in output function that allows the computer to display a
certain text or number on the screen. When printing strings (or text), the syntax is as follows:
std::cout << “Hello World”;
A pair of double quotes (") surround the text to be outputted, and the entire line of code finishes with a semicolon (;).
We can't use the std::cout function right away since we don't have the header file we need to utilize these standard input/output methods. To do so, we'll need to use the built-in library!
Part 2
Now let try the basic escape in C++
Escape sequences are special characters characterized by a backslash () and a letter or symbol beside it. It is used in std::cout statements to show spaces, new lines, or show symbols that cannot be outputted using the normal way of printing.
There are a lot of escape sequences available in C++, but we will only be tackling the most basic ones.
try this code
int main(void) {
std::cout<<"G\n\nO\n\nG\n\nO";
return 0;
}
Part 3
Basic math
Just like your elementary mathematics, C++ also has a similar set of math operations, with an addition of some other set of symbols for specified purposes.
try this code
int main(void) {
int a = -8 ;
int b = -2;
int total = a + b;
std::cout<<"-8+-2="<<total;
return 0;
}
part 4
Now let’s start with something simple! Make a program that accepts a single character and an integer and print it out afterward.
int main(void) {
int a = 4 ;
std::cout<<"C ";
std::cout<< a;
return 0;
}
Leave Learn C++ with me part 1-4 to:
Read more #basicprogramming posts
Best Posts From eleses
We have not curated any of eleses's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.