Hi there,
I'm learning to work with functions,, it isn't my first work, my second.
It crashes continue without reason. It's really simple, so why crashing?
The function readfile is expected to return a string. You are not returning a string.
The compiler doesn't care. It will still treat whatever data is in the place where returned variables go as a string. This means it is treating some random data as a string. When the time comes to destruct that string, it is trying to call a string destruction function on something that is not a string. This is very, very bad.
Your compiler ideally should warn you about this sort of thing. If it does not, you need to turn up the warning level. The g++ compiler says this, for example:
In function ‘std::string readfile(std::string)’:
warning: no return statement in function returning non-void [-Wreturn-type]
Clang says this:
warning: control reaches end of non-void function [-Wreturn-type]
Turn up warnings on your compiler, and listen to what they say.
Your ptogram has underfined behavior because function readfile has no return value thoug it is declared that is returns an object of type std::string. Change its declaration the following way