Skip to content
Advertisement

Strange Output Difference Between GCC and MinGW (C++)

I’m working on a project for a computer science class. I wrote the code and tested it using MinGW, and it works fine. I then copied the code over to the university’s Linux server and tested it there, since that’s what my professor grades assignments on. The output is very different – like it printed out a carriage return in the middle of an output.

The interesting thing is, the issue also appears when compiled and run with Cygwin GCC (32-bit, 4.7.2). Does anyone have any insight as to why this is happening and how to fix it?

Code and a sample input file (to be named lifepath.txt and placed in the same directory as the executable).

JavaScript

I will post a link to an image of the output as a reply, since I don’t have enough rep to have more than two links in a post.

Advertisement

Answer

This is because different line endings, r in Windows’ case means just go to the beginning of the line, when you’re reading data from a file and set the years array. You use keys, not just #### but ####r, and this last symbol is displayed during cout.

So you need to change your code:

JavaScript
Advertisement