Repaired int-to-string conversion in exception message formatting

This commit is contained in:
oparviai 2011-07-17 10:40:27 +00:00
parent 6b2befd571
commit 629a1bbc14

View File

@ -48,6 +48,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdexcept> #include <stdexcept>
#include <string> #include <string>
#include <sstream>
#include <cstring> #include <cstring>
#include <assert.h> #include <assert.h>
#include <limits.h> #include <limits.h>
@ -283,10 +284,11 @@ int WavInFile::read(short *buffer, int maxElems)
// 16 bit format // 16 bit format
if (header.format.bits_per_sample != 16) if (header.format.bits_per_sample != 16)
{ {
string msg = "WAV file bits per sample format not supported: "; stringstream ss;
msg += (int)header.format.bits_per_sample; ss << "\nOnly 8/16 bit sample WAV files supported. Can't open WAV file with ";
msg += " bits per sample."; ss << (int)header.format.bits_per_sample;
throw runtime_error(msg); ss << " bit sample format. ";
throw runtime_error(ss.str());
} }
assert(sizeof(short) == 2); assert(sizeof(short) == 2);
@ -711,10 +713,11 @@ void WavOutFile::write(const short *buffer, int numElems)
if (header.format.bits_per_sample != 16) if (header.format.bits_per_sample != 16)
{ {
string msg = "WAV file bits per sample format not supported: "; stringstream ss;
msg += (int)header.format.bits_per_sample; ss << "\nOnly 8/16 bit sample WAV files supported. Can't open WAV file with ";
msg += " bits per sample."; ss << (int)header.format.bits_per_sample;
throw runtime_error(msg); ss << " bit sample format. ";
throw runtime_error(ss.str());
} }
// allocate temp buffer to swap byte order if necessary // allocate temp buffer to swap byte order if necessary