[英]Multiple user inputs C++
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.我正在尝试获取用户输入,1 或 2,但问题是..当我输入 1 或 2 时,它会自动通过下一步(拖动文件)并完成程序,即使没有拖动任何内容exe。
Simply, Add cin.ignore()
After the First cin
.简单地说,在第一个
cin
之后添加cin.ignore()
。 because when you input the first cin and press (enter) there is a new line \\n
will be created.因为当您输入第一个 cin 并按 (enter) 时,将创建一个新行
\\n
。 and the next getline
will read it.下一个
getline
将读取它。 so it automatically finishes.所以它会自动完成。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.