Can redirecting screen output to a file change the result of C ++ code?

I have very strange behavior with C ++ code. This gives me different results at startup and without redirecting the screen output to a file (playable in cygwin and linux). I mean, if I get the same executable and run it like ./runor run it like ./run >out.log, I get different results!

I use std :: cout for output to the screen, all lines ending with endl; I use ifstream for the input file; I use a stream for output, all lines end with endl.

I am using g ++ 4.

Any idea what is going on?

UPDATE: I hard-coded the input, so "ifstream" is not used, and the problem persists.

UPDATE 2: This is getting interesting. I checked the three variables that are computed initially, and what I get when using with and without redirecting the output to a file

redirected to file: 0 -0.02 0

direct to screen: 0 -0.02 1.04083e-17

Thus, there is a rounding difference in code variables with and without redirection of output!

Now, why will redirection interfere with internal code computation?

UPDATE 3: If I redirect to / dev / null, I get the sam behavior as output directly to the screen, rather than redirecting to a file.

+3
source share
2 answers

nohup, stdin, stdout /dev/null. , stdout ( , stdout - ), , , , .

Edit

, nohup. valgrind, . ( ) , , , , , nohup,

+2

?

Linux / nohup, , cygwin.

, ( ) . "nohup" , "nohup" , , -.

0

Source: https://habr.com/ru/post/1748292/


All Articles