I am observing a weird behavior with this little code :
#include <iostream>
#include <cstdio>
using namespace std;
int get_input()
{
int val;
cin >> val;
return val;
}
int main()
{
cout << "Res = " << get_input() << "\n";
//printf("Res = %d\n", get_input());
}
I have compiled it in the simplest way by this command (I have also tried without the -std option):
g++ -Wall -std=c++17 -o test.exe test.cpp
When I execute the code, I see
Res =
in place to have a blank line waiting for the user entry. The behavior that I am expecting is that the "Res = " is displayed after the return of the get_input function. This is the behavior that I observed when I have used a C++ online compiler (like cpp.sh).
Could anyone explain to me what happens here ?
My gcc version on Debian 11 is :
g++ --version
g++ (Debian 10.2.1-6) 10.2.1 20210110
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Thanks a lot