繁体   English   中英

将无效参数传递给认为无效参数致命的 function?

[英]An invalid parameter was passed to a function that considers invalid parameters fatal?

“Stream Board.exe 中 0x7A3AF2F6 (ucrtbased.dll) 处的未处理异常:无效参数已传递给认为无效参数致命的 function。”

不知道我做错了什么ngl ...

    #include <iostream>
#include <Windows.h>
#include <mmsystem.h>
#include <string>
#include <fstream>

using namespace std;

const int NumberOfSongs = 1;

string SongNames[NumberOfSongs];

int main()
{

    ifstream file("List_Of_Songs.txt");
    if (file.is_open())
    {
        
        for (int i = 0; i < NumberOfSongs; i++)
        {
            file >> SongNames[i];
        }
    }


    bool played=PlaySound(CP_ACP(SongNames[1]), NULL, SND_SYNC);

    cout << SongNames[1] << endl;
}

您将超出数组的范围:

bool played=PlaySound(CP_ACP(SongNames[1]), NULL, SND_SYNC);

您应该访问第一个元素,而不是第二个元素,这在您展示的内容中不存在。

bool played=PlaySound(CP_ACP(SongNames[0]), NULL, SND_SYNC);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM