C++ 调试断言失败。大分配

C++ 调试断言失败。大分配,c++,visual-studio,C++,Visual Studio,我正在尝试记录用户输入的笔记,并将它们存储在一个数组中。验证工作正常,但当我在循环中输入最后一个值时,我得到: Debug Assertion Failed! Expression: "(_Ptr_user & (_BIG_ALLOCATION_ALIGNMENT - 1))==0"&&0 An invalid parameter was passed to a function that considers invalid parameters fatal. 我正在努

我正在尝试记录用户输入的笔记,并将它们存储在一个数组中。验证工作正常,但当我在循环中输入最后一个值时,我得到:

Debug Assertion Failed!
Expression: "(_Ptr_user & (_BIG_ALLOCATION_ALIGNMENT - 1))==0"&&0
An invalid parameter was passed to a function that considers invalid parameters fatal.
我正在努力理解问题在哪里以及如何解决它

#include "stdafx.h"
#include <iostream>
#include <string>

using namespace std;

typedef string noteName;

noteName getNoteName(int i)
{
    bool flag = true;
    noteName Namein;

    do
    {
        cout << "Please enter note name no. " << i + 1 << ": ";
        cin >> Namein;
        cout << "------------------------------------\n";

        if (Namein.length() > 3 || Namein.length() < 2)
        {
            cout << "Sorry, a note name must be 2 or 3 characters long. Please try again.\n";
            flag = false;
        }
        else if (Namein.length() == 3 && Namein[1] != '#')
        {
            cout << "Sorry, the second character of a sharp note name must be #. Please try again.\n";
            flag = false;
        }
        else if ((Namein[0] < 'a' || Namein[0] > 'g') && (Namein[0] < 'A' || Namein[0] > 'G'))
        {
            cout << "Sorry, the first character of a note name must be a letter between A and G. Please try again.\n";
            flag = false;
        }
        else if (isdigit(Namein.back()) == false)
        {
            cout << "Sorry, the last character of a note name must be a number. Please try again.\n";
            flag = false;
        }
        else
        {
            flag = true;
        }
    } while (flag == false);

    return Namein;
}

int main()
{
   const int numNotes = 4;

    noteName NoteNames[numNotes];

    cout << "Hello\n";

    for (int i = 0; i <= numNotes; i++)
    {
        NoteNames[i] = getNoteName(i);
    }

    cout << "Thank you, the note names and lengths you entered were: \n\n";

    for (int i = 0; i <= numNotes; i++)
    {
        cout << i << ". " << NoteNames[i] << "\n";
    }

    cout << "Done!";

    return 0;
}
#包括“stdafx.h”
#包括
#包括
使用名称空间std;
typedef字符串noteName;
noteName getNoteName(int i)
{
布尔标志=真;
注意姓名;
做
{

cout
noteName NoteNames[numNotes];
定义一个数组,其中
NoteNames[numNotes-1]
是您可以访问的最大元素

你走得更远,这样做的行为是未定义的,它表现为你所观察到的崩溃

将循环限制替换为(int i=0;i
或类似值

(类名和变量名的CamelCase约定也与正常情况不同,这使得代码阅读起来很混乱。)

(我还想看看
constexpr int numNotes=4;
:谷歌搜索更多细节。)