C++ getline()忽略数组输出的第一个字母。

C++ getline()忽略数组输出的第一个字母。,c++,c,arrays,cstring,C++,C,Arrays,Cstring,我正在为学校编写一个简单的Mad Libs程序。我发布的代码在数组中迭代搜索某些提示。一旦发现,它就会使用提示询问问题并记录答案。然而,保存我答案的数组忽略了每个单词的第一个字母,除了第一个变量。这是我的代码和数组输出的副本。我知道这很糟糕,但我正在学习 char buffer[256]; int y = 0; //iterates through array looking for answers for(int i = 0;i <= 256;i++) { if(storyArr

我正在为学校编写一个简单的Mad Libs程序。我发布的代码在数组中迭代搜索某些提示。一旦发现,它就会使用提示询问问题并记录答案。然而,保存我答案的数组忽略了每个单词的第一个字母,除了第一个变量。这是我的代码和数组输出的副本。我知道这很糟糕,但我正在学习

char buffer[256];
int y = 0;
//iterates through array looking for answers
for(int i = 0;i <= 256;i++)
{
    if(storyArray[i][0] == '<' && isalpha(storyArray[i][1]))
    {
        for(int x = 0; storyArray[i][x]; x++)
        {
            switch(storyArray[i][x]){
                case '<':
                    cout << "\t";
                    x++;
                    putchar(toupper(storyArray[i][x]));
                    break;
                case '>':
                    cout << ": ";
                        cin.ignore();
                    cin.getline(buffer,256);
                    strcpy(answerArray[y],buffer);
                    y++;
                    break;
                case '_':
                    cout << " ";
                    break;
                default:
                    cout << storyArray[i][x];
                    break;

            }
        }
    }
}
char缓冲区[256];
int y=0;
//遍历数组以查找答案
对于(int i=0;i您告诉它忽略第一个字符。这就是它的作用:

cin.ignore();

把它拿出来,你就没事了。

你想加载什么数据?你能不能也发布一个样本?对于OP: