Help with memory leak

I have a memory leak, whenever using read (option 1) it appears with an À following the text in the file, can someone help find the leak please

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
#define FILENAME "S:\\Unit_5_text_document.txt"
int x;
int choice=0;
string comment;

int main(int argc, char* argv[]) {

while (choice!=5) {

ifstream myFile(FILENAME, ios::in | ios::binary);
//Check #of characters
myFile.seekg(0, myFile.end);
int length = myFile.tellg();
myFile.seekg(0, myFile.beg);
char *Words = new char [length];
//options
cout << "what would you like to do?" << endl;
cout
<< "1.Read - 2.Write - 3.Size of file - 4.Number of characters in the file - 5.End"
<< endl;
cin>> choice;

if (choice==1) {
//reads the file
myFile.read(Words, length);
cout << Words << endl;

}
if (choice==2) {
ofstream myFile(FILENAME, ios::out | ios::binary);
cout << "what would you like to enter into the file?" << endl;
cin >> Words;
myFile.write(Words, sizeof(Words));
}
if (choice==3) {
streampos begin, end;
ifstream myfile(FILENAME, ios::binary);
begin = myfile.tellg();
myfile.seekg(0, ios::end);
end = myfile.tellg();
myfile.close();
cout << "size is: " << (end-begin) << " bytes.\n";
}
if (choice==4) {
myFile.seekg(0, myFile.end);
int length = myFile.tellg();
myFile.seekg(0, myFile.beg);

cout << "Reading " << length << " characters..." << endl;

}
if (choice>5) {
cerr << "Invalid Option" <<endl;
}

}

}
Any time you have something like this: char *Words = new char [length];

You need to do this: delete [] Words;

Topic archived. No new replies allowed.