std::cin does not accept input, program closes immediately

Vermz

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.

Macmade

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Program immediately closes in SDL

From Dev

Why does std::cin accept multiple inputs at the same time?

From Dev

Program With Multiple .cpp Files Closes Immediately, No Error

From Dev

Why does std::cin's extractor operator wait for user input?

From Dev

Why does my Haskell program not accept standard input redirection?

From Dev

Limiting input size with std::setw in std::cin

From Dev

std::thread and input with std::cin in an opengl application

From Dev

Python, pygame program closes immediately when trying to open

From Dev

Console window closes immediately when I run the program

From Dev

What does std::cout << std::cin do?

From Dev

Program closes right after the last input

From Dev

/bin/sh closes immediately without waiting for user input

From Dev

std::cin: empty the input buffer without blocking

From Dev

std::cin infinite loop for wrong input

From Dev

C++ std::cin producing extra input

From Dev

std::cin infinite loop from invalid input

From Dev

std::cin: empty the input buffer without blocking

From Dev

std::cin infinite loop for wrong input

From Dev

Stopping while-loop with std::cin input

From Dev

Program does not accept argument Python

From Dev

Python program does not show the print() and closes itself

From Dev

Using cin, how can I accept a character or an integer as an input?

From Dev

Why does my program accept one integer too many and input one too few?

From Dev

plot in Pandas immediately closes

From Dev

SFML window immediately closes

From Dev

QWizard opens and closes immediately

From Dev

Why does my program not accept a custom exception?

From Dev

Write a shell script that runs an program that requires input with cin

From Dev

std::getline skipping input from std::cin after last occurrence of delimiter, but not with input from std::istringstream

Related Related

  1. 1

    Program immediately closes in SDL

  2. 2

    Why does std::cin accept multiple inputs at the same time?

  3. 3

    Program With Multiple .cpp Files Closes Immediately, No Error

  4. 4

    Why does std::cin's extractor operator wait for user input?

  5. 5

    Why does my Haskell program not accept standard input redirection?

  6. 6

    Limiting input size with std::setw in std::cin

  7. 7

    std::thread and input with std::cin in an opengl application

  8. 8

    Python, pygame program closes immediately when trying to open

  9. 9

    Console window closes immediately when I run the program

  10. 10

    What does std::cout << std::cin do?

  11. 11

    Program closes right after the last input

  12. 12

    /bin/sh closes immediately without waiting for user input

  13. 13

    std::cin: empty the input buffer without blocking

  14. 14

    std::cin infinite loop for wrong input

  15. 15

    C++ std::cin producing extra input

  16. 16

    std::cin infinite loop from invalid input

  17. 17

    std::cin: empty the input buffer without blocking

  18. 18

    std::cin infinite loop for wrong input

  19. 19

    Stopping while-loop with std::cin input

  20. 20

    Program does not accept argument Python

  21. 21

    Python program does not show the print() and closes itself

  22. 22

    Using cin, how can I accept a character or an integer as an input?

  23. 23

    Why does my program accept one integer too many and input one too few?

  24. 24

    plot in Pandas immediately closes

  25. 25

    SFML window immediately closes

  26. 26

    QWizard opens and closes immediately

  27. 27

    Why does my program not accept a custom exception?

  28. 28

    Write a shell script that runs an program that requires input with cin

  29. 29

    std::getline skipping input from std::cin after last occurrence of delimiter, but not with input from std::istringstream

HotTag

Archive