私はMP3ファイルの最初の行を読み込もうとしています(ファイルの先頭に「私はMP3です」というテキストを含むようにこのmp3ファイルを編集しました)。fstream.read()何も読んでいない
これは私がやろうとしているものです:
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
fstream mp3;
mp3.open("05 Imagine.mp3", ios::binary | ios::in | ios::out);
/*mp3.seekg(0, ios::end);
int lof = mp3.tellg();
cout << "Length of file: " << lof << endl;
mp3.seekg(0, ios::beg);*/
//char ch;
//cout << mp3.get(ch) << endl;
char* somebuf;
while(mp3.read(somebuf, 10)) //Read the first 10 chars which are "I'm an MP3 file".
{
//cout << somebuf;
}
return 0;
}
クラッシュしているいくつかの理由で、。ある時点ではクラッシュしませんでしたが、何かを印刷しても何も印刷されませんでした< < somebuf。誰かがこれで私を助けることができますか?
最初の10個の文字を使用すると、11が必要なのか、なぜ – Corbin