我正在尝试制作一个角色定制程序。我想将从 switch 语句接收到的信息存储到 storePlayerRace 变量中。我正在尝试将该信息作为参考传递。我不知道这是否是正确的做法。这个问题真的很困扰我,因为它应该很简单。每次我运行它时,cout 语句都不会向屏幕输出任何文本。我希望选择的比赛输出到屏幕上。非常感谢任何相关的帮助!**我试图打破 switch 语句的范围。
#include <iostream>
#include <Windows.h>
#include <string>
using namespace std;
string characterName(string x){
return x;
}
string characterRace(string &x){
return x;
}
int main()
{
string name;
string storePlayerName;
string storePlayerRace;
int race;
cout << "<------Character Creation------->" << endl;
cout << "\n\n Enter Character name " << endl;
getline(cin,name);
storePlayerName = characterName(name);
cout << "\n Select Race " << endl;
cout << "1: White";
cout << "\n2: Black\n";
cin >> race;
switch(race){
case 1:
{
string white;
storePlayerRace = characterRace(white);
}break;
case 2:
{
string black;
storePlayerRace = characterRace(black);
}break;
}
cout << storePlayerRace << endl;
cout << "End of Program" << endl;
getchar();
system("PAUSE");
}