【发布时间】:2012-08-02 18:22:18
【问题描述】:
我正在编写一个 c++ 程序来安装我放在多台计算机上的某些程序。我在代码中放置了一个部分,允许用户选择他们想要的安装。我对 c++ 非常生疏,所以我无法接受用户输入。我愿意接受有关更好方法的建议,我相信有几个。
int allOrSelect;
std::cout << "Press 1 if you want all software, press 2 if you want to select";
std::cin >> allOrSelect;
if(allOrSelect == 1)
{
std::cout<< "all software installing ..." <<std::endl;
}
if(allOrSelect == 2)
{
std::cout << "Please select from the following list";
std::cout << "software 1";
std::cout << "software 2";
std::cout << "software 3";
std::cout << "software 4";
std::cout << "Type the appropriate numbers separated by space or comma";
//this is where trouble starts
//I've tried a few different ways to take the user input
//i tried using vector array, but never got it working, but i figured there had to
//be a simpler way. also tried variations of cin.whatever
}
如果您需要更多信息,请告诉我,并提前致谢。
【问题讨论】:
-
查看
std::cin的输入和std::endl以在每个文本字符串的末尾输出一个换行符。