Z
ZikO
Hi.
Im using C++ Compiler as below:
g++ (GCC) 4.3.0 20080305 (alpha-testing) mingw-20080502
Copyright (C) 2008 Free Software Foundation, Inc.
Im writing the simple program which is supposed to give info about sound
wave file. It checks whether a file is a wave format (4 ASCII bytes
should be like {'R','I','F','F'}) and then it reads what the size of the
file is (another 4 bytes). However, I found difficult to understand how
to use both get() and read() functions properly which are in <fstream>
library.
there is the code below in which I check if file starts with "RIFF". I
have used waveFile.get() function to obtain 4 bytes from the input
stream, although I wanted read() before. I had to use get() because if I
used read() instead the program would go straight to else branch and
display "This is not a wave file", even if it is.
Any suggestions why read() does not work here?
Thanks.
PS. The test file can be found here:
http://rapidshare.de/files/44749739/test.wav.html
Im using C++ Compiler as below:
g++ (GCC) 4.3.0 20080305 (alpha-testing) mingw-20080502
Copyright (C) 2008 Free Software Foundation, Inc.
Im writing the simple program which is supposed to give info about sound
wave file. It checks whether a file is a wave format (4 ASCII bytes
should be like {'R','I','F','F'}) and then it reads what the size of the
file is (another 4 bytes). However, I found difficult to understand how
to use both get() and read() functions properly which are in <fstream>
library.
there is the code below in which I check if file starts with "RIFF". I
have used waveFile.get() function to obtain 4 bytes from the input
stream, although I wanted read() before. I had to use get() because if I
used read() instead the program would go straight to else branch and
display "This is not a wave file", even if it is.
Any suggestions why read() does not work here?
Thanks.
PS. The test file can be found here:
http://rapidshare.de/files/44749739/test.wav.html
Code:
..ifstream waveFile("test.txt");
..int filePointer = 0;
.. char temp[5] = {0,0,0,0};
.. if(waveFile.get(temp,4)) {
.. // cout << "stream pointer = " << waveFile.tellg() << endl;
.. filePointer += 4;
.. char waveChunk[] = {"RIFF"};
.. if(strcmp(temp, waveChunk)) {
.. cout << "This is a wave file." << endl;
.. }
.. else {
.. cout << "This is not a wave file" << endl;
.. return 0;
.. }
.. }
.. else
.. checkStream(waveFile);
..
.. int roz;
.. waveFile.seekg(filePointer);
.. if(waveFile.read(reinterpret_cast<char*>(&roz), 4)) {
.. filePointer += 4;
.. roz += 8;
.. cout << "The size is: " << roz << endl;
.. }
.. else
.. checkStream(waveFile);