• Welcome to Valhalla Legends Archive.
 

Cin??

Started by Mitosis, November 19, 2003, 07:01 AM

Previous topic - Next topic

Mitosis

In the book I have c++ for dummies, Im at the part where its talking about the "cin", Im kind of confused like it says you can input stuff in there, but Im not sure how to. Like do you put variables inside of it or what?

iago

cin reads input from the keyboard

int a;
cin >> a;

That'll wait for them to enter a number and press enter, then put that value in a.  Most variable types can be used, like char[], double, etc.
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


CupHead

Technically you can overload it to use any data type, but that's another topic.

wut

the >> operator can only be used to read one line as cannot process whitespace characters; the global function getline() is also available to read input, e.g.
char var[100];
                cin.getline(var, 99);

Mitosis

So what happens if you press a?

MoNksBaNe_Agahnim

example...
void main() [main function that doesn't need to return anything]
{

int x; [your variable is an integer and is delcared as x as is used in alg]

cout << "Input the value of x: "; [this is outputting whats in the quotes]

cin >> x; [this is what accepts your input -- note the direction of ">>" opposite of cout's]

cout << endl << "value of x is now: " <<  x; [skips down a line and outputs your new value of x]

}
----------------------------
{output on screen}
Input the value of x: 2
value of x is now: 2
----------------------------

Kp

Quote from: MoNksBaNe_Agahnim on November 19, 2003, 06:48 PM
void main() [main function that doesn't need to return anything]
As was bashed to death in another thread, this prototype is wrong.  The correct and portable signature for main is int main (int, char **).
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

iago

Quote from: Kp on November 19, 2003, 09:40 PM
Quote from: MoNksBaNe_Agahnim on November 19, 2003, 06:48 PM
void main() [main function that doesn't need to return anything]
As was bashed to death in another thread, this prototype is wrong.  The correct and portable signature for main is int main (int, char **).

Or
int main( void ); is acceptable, isn't it?
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


Adron

I suggest developing a language named VC++ which is like C++ except it supports Void main - "Void main C++"!

Banana fanna fo fanna


Mitosis

Oh boy press any key to continue and exit.

Banana fanna fo fanna

That's exactly what should happen. Maybe you should check the contents of the variable now?

Mitosis

int a;
cin >> a;
cout << "hello" << endl;

When I press anything Hello will show. How would I be able to make like questions?

Banana fanna fo fanna

cout the question first, then cin the answers.

toxic

getline(cin,apstring) > cin >> *.*