C++ std::string 當作 Binary Data Buffer

摘要:C++ std::string 當作 Binary Data Buffer


#include <iostream>
#include <cstdio>
using std::string;

int main(int argc, char* argv[])
{
	FILE *fp = NULL;
	FILE *fout = NULL;

	char 	szBuffer[256];
	string 	strBuff;
	int	nLength, nTotalSize = 0;
	
	fp = fopen("12345.pcm", "rb");
	fout = fopen("12345.out", "wb");

	while(!feof(fp))
	{
		nLength = fread( szBuffer , 1 , 256 , fp );
		nTotalSize += nLength;
		strBuff.append(szBuffer, nLength);
        }
	fclose(fp);
	
	fwrite(strBuff.data(), 1, ,strBuff.length(), fout);
	fclose(fout);


	return 0;
}