I am trying to store the first 4 chars of a .awv file using the std::fgetc function
This is what I have
FILE* WAVF = fopen(FName, "rb");
std::vector<std::string> ID;
ID[4];
for (int i = 0; i < 4; i++)
{
ID[i] = fgetc(WAVF);
}
I keep getting this error:
Exception thrown at 0x00007FF696431309 in ConsoleApplication3.exe:
0xC0000005: Access violation writing location 0x0000000000000010.
Your program has undefined behavior!
Your vector
IDis empty. By callingoperator[]on an emptystd::vector, invoking an undefined behavior. You got lucky that your program got crashed, saying "Access violation".You need instead:
However, in your case,
std::fgetcreturnsintger asSo you might want the data structures such as
std::vector<char>or (at best)std::string.