Output and Input Data
C++ uses "cout <<" for output (strings, streams, numbers,
objects etc).
C++ use "cin >>" for input. for example:
cin >> name; So "cin >>" is the opposite of "cout
<<".
The following is an example of how to use "cout <<" and
"cin >>":
#include <iostream>
using namespace std;
int main(){
string name;
cout << "Hello. Whats your name?";
cin >> name;
cout << "Hello "<< name;
}
This program uses "cout <<" to ask an user "Whats
your name". When the user inputs his name. It reads the name of the
user and displays it out.
Comments
Comments are used by programmers to write notes, descriptions within
the source code. Comments are ignored by the compiler. When you have one
line comment, you can write it with two forward slashes:
//this is my comment
If you have multiple comments, you can write them within "/*"
and "*/":
/*
These are my comments
...
*/
For example, in the above program, we can insert comments as following:
/*
my first C++ program
"Hello Whats your name?"
*/
#include <iostream>
using namespace std;
int main(){ //main function
string name;
cout << "Hello. Whats your name?";//print out
cin >> name; // input
cout << "Hello "<< name;
}
|