如何在数组中存储用户字符串,C++

如何在数组中存储用户字符串,C++,c++,arrays,variables,input,store,C++,Arrays,Variables,Input,Store,我正在建立一个选择你自己的冒险 所以基本上,在用户输入他们的名字后,我希望playerlistswitch语句存储输入basePlayer[]的内容 此外,如果您要运行此功能,则必须在输入名称后单击向下箭头才能进入playerList菜单,因为它有点问题 非常感谢您的帮助 谢谢,, 迈克 尝试从程序中删除语句cin.get,因为cin>>name输入了名称,因此cin.get没有任何用处。它有效吗?好的,我会补充这一点作为答案。请接受好的,全部编辑。^^顺便说一句,这将运行,可能更容易看到我所说

我正在建立一个选择你自己的冒险

所以基本上,在用户输入他们的名字后,我希望playerlistswitch语句存储输入basePlayer[]的内容

此外,如果您要运行此功能,则必须在输入名称后单击向下箭头才能进入playerList菜单,因为它有点问题

非常感谢您的帮助

谢谢,, 迈克


尝试从程序中删除语句cin.get,因为cin>>name输入了名称,因此cin.get没有任何用处。

它有效吗?好的,我会补充这一点作为答案。请接受好的,全部编辑。^^顺便说一句,这将运行,可能更容易看到我所说的内容。如果您减少代码的大小以突出显示代码中存在问题的部分,这将是值得注意的。我建议您首先使用调试器来完成代码,如果有具体错误,修改问题。在我确定答案后,我还能再问你一个问题吗?当然。你想问什么?好的,那么你的问题到底是什么?我应该在你的答案中写些什么?我只是抄过你的帖子吗?我想你不需要发布你的答案,因为你已经从这篇帖子中得到了答案。你只需要在我的答案中点击“向上投票”和“向下投票”计数器下方的勾号。
#include <iostream>
#include <string>
#include <windows.h>
#include <cmath>
#include <cstring>
#include <cstdlib>

using namespace std;

int main(){
Beep(251.63,100);
Beep(329.63,100);
Beep(392,100);
Beep(251.63,100);
Beep(329.63,100);
Beep(392,100);
Beep(251.63,100);
Beep(329.63,100);
Beep(392,100);

string playerList[6] = {"Abbot", "Sear", "Hellion", "Vagabond", "Knave","##QUIT##"};
string cityList[4] = {"city1","city2","city3","city4"};
string spiritList[4] = {"spirit1","spirit2","spirit3","spirit4",};
string yesNo[2] = {"yes","no"};
string name;
string player;
string city;
string spirit;
string basePlayer[4];
    basePlayer[0] = name;
    basePlayer[1] = player;
    basePlayer[2] = city;
    basePlayer[3] = spirit;


int pointer = 0;

while(true){

cout << "What is your name?" << endl;
cin >> name;
cout << "your name is " << name << "?" << endl;
basePlayer[0] = name;
cout << basePlayer[0];


int pointer = 0;

while(true){
    system("cls");

    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 5);
    cout << basePlayer[0]<<" please choose your Adventurer:\n*tab* for  description\n\n";

    for (int row = 0; row < 6; ++row){
        if(row == pointer){
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 11);
            cout << playerList[row] << endl;}

        else{
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 5);
            cout << playerList[row] << endl;}}

 while(true){

  if (GetAsyncKeyState(VK_UP) != 0){
        Beep(800,50);
    pointer -= 1;
    if (pointer == -1){
        pointer = 0;}
            break;}

 else if (GetAsyncKeyState(VK_DOWN) != 0){
        Beep(800,50);
    pointer += 1;
    if (pointer == 6){
        pointer = 0;}
            break;}

 else if (GetAsyncKeyState(VK_TAB) != 0){
        Beep(1200,50);
        Beep(1000,50);

    switch(pointer){
    case 0:{
        system("cls");
        cout << "AbbotFacts.\n\n*Enter* to become the Abbot\n*ArrowDown* to      return to TitleScreen";
        Sleep(1000);
    }
        break;
    case 1:{
        system("cls");
        cout << "SearFacts.\n\n*Enter* to become the Sear\n*ArrowDown* to  return to TitleScreen";
        Sleep(1000);
    }
        break;
    case 2:{
        system("cls");
        cout << "HellionFacts.\n\n*Enter* to become the Hellion\n*ArrowDown* to return to TitleScreen";
        Sleep(1000);
    }
        break;
    case 3:{
        system("cls");
        cout << "VagabondFacts.\n\n*Enter* to become the Vagabond\n*ArrowDown* to return to TitleScreen";
        Sleep(1000);
    }
        break;
    case 4:{
        system("cls");
        cout << "KnaveFacts.\n\n*Enter* to become the Knave\n*ArrowDown* to return to TitleScreen";
        Sleep(1000);
    }
        break;
    case 5:{return 0;}
        break;
        break;}}

else if (GetAsyncKeyState(VK_RETURN) != 0){
        Beep(1000,50);
        Beep(1200,50);


    switch(pointer){
    case 0:{
        system("cls");
        cout << "You have chosen the Abbot"<< endl;
        Sleep(1000);
    }

        break;
    case 1:{
        system("cls");
        cout << "You have chosen the Sear"<< endl;
        Sleep(1000);
    }
        break;
    case 2:{
        system("cls");
        cout << "You have chosen the Hellion"<< endl;
        Sleep(1000);
    }
        break;
    case 3:{
        system("cls");
        cout << "You have chosen the Vagabond" << endl;
        Sleep(1000);
    }
        break;
    case 4:{
        system("cls");
        cout << "You have chosen the knave"<< endl;
        Sleep(1000);
    }
        break;
    case 5:{return 0;
    break;}
    break;}}
 }
  Sleep(150);
 }
 }
 }