Overview of C++
Overview of C++
#include <iostream>
using namespace std;
int main()
{
cout << “Ephrem Computer Tutor!";
return 0;
}
Line 3: A blank line. C++ ignores white space, is made for better clarity and readablity.
Line 4: Another thing that always appear in a C++ program, is int main(). This is called a
function. Any code inside its curly brackets {} will be executed.
Line 5: cout (pronounced "see-out") is an object used together with the insertion operator (<<)
to output/print text. In our example it will output “Ephrem Computer Tutor".
Line 7: Do not forget to add the closing curly bracket } to actually end the main function.
#include <iostream>
int main() {
std::cout << “Ephem Computer
Tutor!";
return 0;
}
It is up to you if you want to include the standard namespace library or not.
6
EPHREM T. GOFA SAWLA, ETHIOPIA
1. C++ Output (Print Text)
The cout object, together with the << operator, is used to output values/print text:
#include <iostream>
using namespace std;
Ephrem Computer Tutor!
int main()
{
cout << “Ephrem Computer Tutor!";
return 0;
}
#include <iostream>
using namespace std; Ephrem Computer Tutor!
Streaming C++
int main() {
cout << “Ephrem Computer Tutor! \n";
cout << “Streaming C++";
return 0;
}
I am 29 years old.
cin is a predefined variable that reads data from the keyboard with the extraction operator
(>>).
In the following example, the user can input a number, which is stored in the variable x. Then
we print the value of x:
int x;
cout << "Type a number: ";
cin >> x;
cout << "Your number is: " << x;
Thank you!!!