You may not want to use that code for a number of reasons including:
Copying someone else's code for your homework is cheating
It corrupts the data by discarding the newline delimiters
It's a memory hog if the files are large (uses double the file size)
It does horribly inefficient string concatenations
It returns the file size in bytes, which may not be the number of characters, depending on the default encoding, and includes newline delimiters.
The original code is a far better starting place, once all its silly source errors are fixed (capitalisation of "string" or "Out", missing return type etc). It's hard to understand how you can get a stack overflow error with code that can't be compiled.