我正在尝试通过按f1,f2,f3等数字来使switch语句在控制台上显示一些内容。我愿意停止使用switch语句,但这是我最熟悉的,因此,如果解决方案将switch语句保留在其中。我不能不写更多而发布它。抱歉忘了,这是WINDOWS 10
#include <iostream>
#include <istream>
#include <fstream>
#include <string.h>
#include <conio.h>
using namespace std;
int main() {
char gun;
char att;
cout << "Guns" << endl;
cout << "[F1] AK" << endl;
cout << "[F2] MP5" << endl;
cout << "[F3] M2" << endl;
cout << "[F4] SAR" << endl;
cout << "[F5] Tommy" << endl;
cout << "[F6] Custom" << endl;
cin >> gun;
cout << "Attachnments" << endl;
cout << "[F7] Holosight" << endl;
cout << "[F8] Simplesight" << endl;
cout << "[F9] Silencer" << endl;
cout << "[F10] 8x Zoom Scope" << endl;
cout << "[F11] 16x Zoom Scope" << endl;
cout << "[F12] No Attachment" << endl;
cin >> att;
system("CLS");
switch (gun) {
case'1':
cout << "Current Gun: AK" << endl;
break;
case'2':
cout << "Current Gun: MP5" << endl;
break;
case'3':
cout << "Current Gun: M2" << endl;
break;
case'4':
cout << "Current Gun: SAR" << endl;
break;
case'5':
cout << "Current Gun: Tommy" << endl;
break;
case'6':
cout << "Current Gun: Custom" << endl;
break;
}
switch (att) {
case'A':
cout << "Current Attachment: Holosight" << endl;
break;
case'B':
cout << "Current Attachment: Simplesight" << endl;
break;
case'C':
cout << "Current Attachment: Silencer" << endl;
break;
case'D':
cout << "Current Attachment: Muzzel Boost" << endl;
break;
case'E':
cout << "Current Attachment: Muzzel Break" << endl;
break;
case'F':
cout << "Current Attachment: 8x Zoom Scope" << endl;
break;
case'G':
cout << "Current Attachment: 16x Zoom Scope" << endl;
break;
case'H':
cout << "Current Attachment: Lasersight" << endl;
break;
}
}```
the numbers and letters are just place holders for the f1 f2 and f3 etc.
没有功能键的标准表示。因此,首先计算一下在按下Fn时,哪些字符到达您的应用程序。它很可能超过一个字符。