char* readFromFile(char* location)
{
int total = 0;
ifstream ifile = ifstream(location);
ifile.seekg(0, ifile.end);
total = ifile.tellg();
cout << "Total count" << total << endl;
char* file = new char[total+1];
ifile.seekg(0, ifile.beg);
ifile.read(file, total+1);
cout <<"File output" << endl<< file << "Output end"<<endl;
return file;
}
здесь он печатает данные файла, но также добавляет некоторое количество мусора. как мне его исправить?C++ ifstream добавляет данные мусора при чтении из текстового файла
Null прекратить действие вашей строки? –