简体   繁体   中英

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

"Unhandled exception at 0x7A3AF2F6 (ucrtbased.dll) in Stream Board.exe: An invalid parameter was passed to a function that considers invalid parameters fatal."

No idea what ive done wrong 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;
}

You are going out of bounds of an array:

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

You should access the first element, not the second, which does not exist from what you showed.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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