I've got a file to read, well, read to a vector<short> m_vVoice;
we all know that
1 ) ios_base->ios->istream->ifstream
2 ) istream& read ( char* s, streamsize n );
So, I tried the following code
The first two methods are trying to read a whole/entire block of memory directly into vector<short> m_vVoice, but failed; the 3rd method is running, but it actually read data one by one. It's pretty slow, which is not what I expected.
ifstream ifs (fn.c_str (), ios::binary);
// 1) -- fail
// 2) -- fail
// vector<short>::iterator currentPos = this->m_vVoice.begin();
// ifs.read (reinterpret_cast <char *>(¤tPos), this->m_iVoiceLength * sizeof(short));
// 3) -- works, but too slow
// http://www.thescripts.com/forum/thread133371.html, clumsy way
for(int i = 0; i < this->m_iVoiceLength; i++)
ifs.read( reinterpret_cast <char *> (&this->m_vVoice), sizeof (short) );
Can anybody help??