My function reads a file and puts it into a string in order for me to process it. I need to read just before EOF, obviously. The problem is that the EOF character is also put inside the string and I can't find a way to bypass it, since it leds other parts of the program to fail. I link the function below.
string name_to_open, ret = string(); ifstream in; getline(cin, name_to_open); in.open(name_to_open.c_str()); if (!in.is_open()) { cout << "Error." << endl; return string(); } else { ret += in.get(); while (in.good()) { ret += in.get(); }; }; in.close(); return ret; The function reads fine until the end of the file, then appends EOF and \0. How can I solve the problem? Does the EOF character work fine in controls? I also tried to put a line ret[ret.size() - 1] = '\0'; at the end of the cycle, but this doesn't seem to work either.