GCC giving different results in Windows and WSL

Revision en9, by Robin, 2020-04-07 20:32:52

So I was debugging this code and managed input/outputs in separate files. I ran the same code with same flags in codeblocks and WSL ubuntu 18.04, they gave me two different outputs.

My Code


using namespace std;

int main() {
#ifdef ROBIN
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif // ROBIN
    int t, d = 0;
    cin >> t;
    while (t--) {
        string ss, tt;
        getline(cin, ss);
        getline(cin, tt);
        cout << "SS: " << ss << endl;
        cout << "TT: " << tt << endl;


Tom Marvolo Riddle
I am Lord Voldemort
I am not Harry Potter
Hi Pretty Roar to man
Harry and Voldemort
Tom and Jerry and Harry

Output (Code::Blocks)

SS: Tom Marvolo Riddle
TT: I am Lord Voldemort
SS: I am not Harry Potter
TT: Hi Pretty Roar to man
SS: Harry and Voldemort
TT: Tom and Jerry and Harry

Output (WSL)

TT: Tom Marvolo Riddle
SS: I am Lord Voldemort
TT: I am not Harry Potter
SS: Hi Pretty Roar to man
TT: Harry and Voldemort

I would appreciate it if someone gives me a proper explanation of this. Thanks.


  Rev. Lang. By When Δ Comment
en9 English Robin 2020-04-07 20:32:52 73
en8 English Robin 2020-04-07 20:31:57 44
en7 English Robin 2020-04-07 20:30:58 64
en6 English Robin 2020-04-07 20:27:39 769
en5 English Robin 2020-04-07 20:24:31 93
en4 English Robin 2020-04-07 20:23:02 81
en3 English Robin 2020-04-07 20:21:33 1748 Tiny change: 'ts. <br>\n~~~~~\n#' -> 'ts. <br>\n\n~~~~~\n#'
en2 English Robin 2020-04-07 20:16:09 29
en1 English Robin 2020-04-07 20:15:40 429 Initial revision (published)