簡體   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