Sorry if this has been asked before but I have tried to find a solution elsewhere. I am using the getline function to receive input from the keyboard and save it in a text file. The problem is that it insists on printing a null character (the square box thingy) on the end of the line each time the program is run. How do I stop this? Here is my code:
string str;
ofstream myFile("textfile.txt", ios::app);
cout << "Enter text: " << endl;
getline(cin,str);
if(! myFile) //check file open
{
cout << "Error opening file" << endl;
return -1;
}
myFile << str << endl; //write file
myFile.close(); //close file