I tried to get a string as an input with cin
and it worked, but when I tried to get an int
as an input just after the string the console won't ask for it and the program shuts down. Here's my code:
#include <iostream>
#include <string>
using namespace std;
void main(void)
{
string a, b;
int c, d, e;
cout << "Enter two words \n";
cin >> a, b;
cout << "Enter three int";
cin >> c, d, e;
cout << c*d;
}
This code won't let me enter the second input, but I can see the second output before the program shuts down.
Your code is wrong:
cin >> a, b;
will not give you what you expect. In you need to read to strings from cin
, use:
cin >> a;
cin >> b;
The same applies for the other types.
Also note that:
void main( void )
is not correct. main
must return an int
:
int main( void )
{
return 0;
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments