16,472
社区成员
发帖
与我相关
我的任务
分享
#include "stdafx.h"
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int lenght;
char* buf;
ifstream infile;
infile.open("example.txt", ios::binary);
infile.seekg(0, ios::end);
lenght = infile.tellg();
infile.seekg(0, ios::beg);
buf = new char[lenght];
infile.read(buf, lenght);
infile.close();
cout.write(buf, lenght);
cout<<endl;
string str1(buf);
cout<<str1<<endl;
cout<<lenght<<endl;
cout<<strlen(buf)<<endl;
system("pause");
return 0;
}