I want to extract some integers from a file using C++, but I am not sure if I am doing it correctly.
My code in VB6 is the following:
Redim iInts(240) As Integer
Open "m:\dev\voice.raw" For Binary As #iFileNr
Get #iReadFile, 600, iInts() 'Read from position 600 and read 240 bytes
My conversion to C++ is the following:
vector<int>iInts
iInts.resize(240)
FILE* m_infile;
string filename="m://dev//voice.raw";
if (GetFileAttributes(filename.c_str())==INVALID_FILE_ATTRIBUTES)
{
printf("wav file not found");
DebugBreak();
}
else
{
m_infile = fopen(filename.c_str(),"rb");
}
But now I don’t know how to continue from there, and I also don’t know if “rb” is correct.
I don’t know how VB reads a file but if you need to read integers from a file try:
Or you can use the C++ way using ifstream.
Full example with streams (note, you should add error checking):