c++ - How to get consistent responses from fstream? -


When I read the information through FSTR, then two separate programs have come twice, that my The input given to the program is static, even if no given file changes.

In my most recent program, which is related to audio-reading, I am doing a simple check on the first four letters in the file. These letters are considered as RIFF, which are they - I checked is.

Therefore, to see the format of a given binary file, I buffer the first four characters and see if they are similar to 'RIFF'.

  Four buffers [4]; Std :: ifstream in (fn, std :: ios :: binary); In.read (buffer, 4); If (buffer! = "Riff") {// Always Wrong ATM Stud :: COAT & LT; & Lt; "INVALID WAV file:" & lt; & Lt; Buffer & lt; & Lt; Std :: endl; }  

When I made the program for the first time, I remember this work properly. Now though, I get an error through my own cot:

  INVALID WAV FILE: RIFFýfK  

Do anyone have any ideas Which has gone wrong? Perhaps the way to make Fremmim more consistent?

You are reading 4 characters but not adding a zero terminator Apart from this, your comparison is wrong because you are not comparing string similarity, you should:

  four buffer [5]; Std :: ifstream in (fn, std :: ios :: binary); In.read (buffer, 4); Buffer [4] = '\ 0'; // Finally add a zero-terminator (if the buffer {'R', 'I', 'F', 'F', '0'} . Std :: cout & lt; & Lt; "INVALID WAV file:" & lt; & Lt; Buffer & lt; & Lt; Std :: endl; }  

Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -