Click to See Complete Forum and Search --> : Cin, Cout. can someone help a newb.
factor777
Jan 10th, 2001, 07:14 PM
I want to know how to use Cin and Cout Correctly.
HarryW
Jan 10th, 2001, 07:29 PM
#include <iostream>
using namespace std;
int main()
{ cout << "Some output text" //send a string to the console
<< endl; // send a newline character
int a;
cout << "Enter an integer: "; //prompt user for input
cin >> a; //get user input and put it in variable a
cout << endl << endl //go down a couple of lines
<< "You entered the integer " //output a string
<< a //output an integer
<< endl; //another newline
return 0; //end function
}
That's basically how it works. Nothing fancy.
<< is the stream insertion operator
>> is the stream extraction operator
cin and cout are streams. cin is the input stream, and cout is the output stream. You insert things into the output stream and extract them from the input stream. Makes sense, really :)
Vlatko
Jan 11th, 2001, 08:34 AM
You may encounter problems using cin with multi-word input. In that case you use cin.getline
char text[256];
cout<<"Enter Sentence"<<endl;
cin.getline(text,256);
cout<<text<<endl;
MPrestonf12
Jan 14th, 2001, 08:46 PM
you could also use
printf to print text out(like cout)
scanf - to take input from the keyboard.
AS far as i see they are the same as cout and cin but i found these easier to use
Vlatko
Jan 15th, 2001, 05:08 AM
'cout' and 'cin' are easier to use than 'printf' and 'scanf'. 'printf' and 'scanf' have more complex sintax, if you want to display a value have to use %d or %s or..
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.