EDIT: Problem solved. @sth asked whether or not I was forgetting to delete the object I might have created with "new". He was right! I was forgetting it. And fixing that indeed fixed the issue. I guess it's something that Visual Studio was doing for me and Linux wasn't.
EDIT 2: Code is removed due to this being a school project and potential issues of plagiarism even though I wrote the code myself. Also the issue seems to be unrelated to the specifics of my code and more of a general c++ use case of new and delete.
Exact same code behaves differently on Visual Studio 2013 (installed on Windows) and ssh server of my school in which I use g++ to compile the code. Code compiles without an error and works as intended except for 1 part. It writes 1 line less when writing the contents of an array to a file line by line.
If the array has 10 elements Visual Studio compiled code creates the "sorted.txt" file with 10 lines and all of them hold exactly 1 integer. No empty lines. Ssh compiled code still creates 10 lines however the last line is empty. So there is actually 1 integer missing in my "sorted.txt" file. My assignment will be compiled on this server when being graded so this might be a problem.