Answer:
Difference between "cin" & "cout" is:
"cout"
"cin"It stands for console output. Console means the computer display screen. The 'cout' is a predefined object. It is used as an output statement to display output on the computer screen. It I a part of iostream header file.
Flow of data from one location to another location is called stream .The 'cout' is the standard output stream.
The syntax of 'cout' is;
cout<< const1/vari1,.........................;
cout name of output stream object.
<< put to operator or insertion operator. It directs the output to the output device.
const1/var1, These are the constants and variables that are used to show output on the screen.
For e.g.
cout<<"one kilobyte="<<1024<<" bytes";
In above example two string constants, one numeric constant and three put to operators are used and its output will be: One kilobyte= 1024 bytes.
It stands for console input. It is an input stream. It is used as input statement to get input from the keyboard during execution of the program.
When an input statement is executed, the computer waits to receive an input from the keyboard. When the value is typed and enter key is pressed the value is assigned to the variable and control shifts to next statement.
It is also the part of iostream header file.
The syntax of 'cin' is:
cin>>var1 [>>var2...];
cin represents the object used as an input stream and gets the value from keyboard.
>> Extraction operator or get from operator. Its get an input from the input device and assigned t the variable.
var1, var2 represents list of variables and each variable I separated by '>>'
At least one variable on the right-hand-side of the ">>"operator must be used.
For e.g.
cin>>a>>b>>c;
cout and cin are synonymous with stdout and stdin, the global standard output and input streams, respectively. Output is normally directed to the screen (<<) while input is directed from the keyboard (>>).
When a program is run, three streams are opened automatically: stdin, stdout and stderr. By default, these streams are directed to the console (keyboard and screen). Thus, by default, user input will generally come from the keyboard, while program output and error messages will be sent to the screen.
cin, cout and cerr are synonymous with stdin, stdout and stderr, respectively. Since they are all streams there is no real difference between them, other than that cin is intended for input while cout and cerr are intended for output. It is clearly important that input, output and errors are all treated separately, and consistently, hence the need for separate streams.
cin( console input) and cout(console output) are methods of the class iostream. cin is used for getting data from the console while cout is used for printing data into the console.
For more detailed explanation, visit the link below:
#include <iostream>
int main()
{
std::cout << "Hello world!" << std::endl;
return(0);
}
Console output. It corresponds with the standard output stream (stdout) and usually means all output is directed to the screen.
std::cout<<42<<std::endl;
I believe, you can use C-function - printf().
std::cout<<"computer"<<std::endl;
#include <iostream.h> main() { int a; cout<<"enter a number : "; cin>>a; cout<<endl; if (a%2-1) cout<<"it is a prime number"; else cout<<"it is not a prime number" return 0; } ------------------------------------------ output: enter a number : 30 it is a not a prime number
#include<iostream> int main() { std::cout << "Your name"; }
cout<<"______": cin >>__>>__; [example cout<<"enter no."; cin>>a>>b; ]
#include<iostream> int main() { using namespace std; char c='A'; do { cout<<c; }while(c++<'Z'); cout<<endl; }
std::cout<<42<<std::endl;
I believe, you can use C-function - printf().
#include<iostream> int main() { int num1, num2; std::cout << "C++ addition program" << std::endl; std::cout << "Enter a number: "; std::cin >> num1; std::cout << "Enter another number: "; std::cin >> num2; std::cout << "The sum is " << num1 + num2 << std::endl; }
std::cout<<"computer"<<std::endl;
#include <iostream.h> main() { int a; cout<<"enter a number : "; cin>>a; cout<<endl; if (a%2-1) cout<<"it is a prime number"; else cout<<"it is not a prime number" return 0; } ------------------------------------------ output: enter a number : 30 it is a not a prime number
#include<iostream> in main() { std::cout << "Hello World\n"; }
#include<iostream> int main() { std::cout << "Your name"; }
#include<iostream> int main() { int x=0, y=1; std::cout<<x<<" "; std::cout<<y<<" "; while( y<1000000 ) { std::cout<<(y+=x)<<" "; x=y-x; } std::cout<<std::endl; return(0); }
#include<iostream> int main() { int x=0, y=1; std::cout<<x<<" "; std::cout<<y<<" "; while( y<1000000 ) { std::cout<<(y+=x)<<" "; x=y-x; } std::cout<<std::endl; return(0); }
void line(int length) { for(int i=0; i<length; ++i) std::cout<<'_'; std::cout<<std::endl; }