-2
int main() {

std::cout << "Press 1 to convert a Scobalula HUSKY Map Obj (divide position by 2.54) or 2 to convert w/o division. \n";
cin >> numinput;

std::cout << "Drag the obj file you want to convert and press enter.\n";
std::string fileinput;

std::getline(std::cin, fileinput);

I am trying to get a user input, either 1 or two, but then the problem is..when I type 1 or two, it automatically passes the next step (drag the file) and finishes the program even though nothing has been dragged on the exe.

  • You never check *what* the user inputs before proceeding. – Jesper Juhl Mar 11 '19 at 17:38
  • Possible duplicate of [Why does std::getline() skip input after a formatted extraction?](https://stackoverflow.com/questions/21567291/why-does-stdgetline-skip-input-after-a-formatted-extraction) (I should have dupe hammered this question) – πάντα ῥεῖ Mar 11 '19 at 18:26

1 Answers1

0

Simply, Add cin.ignore() After the First cin. because when you input the first cin and press (enter) there is a new line \n will be created. and the next getline will read it. so it automatically finishes.

Atef Magdy
  • 90
  • 9
  • Of course this only works if user for instance does not enter a space after the first choice... – hyde Mar 11 '19 at 18:53