If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Re: Why can't I see the output of my C++ code?

Code:

cin>> c >> n;

will read the two numbers but not the terminating lf/cr. This is still in the buffer. So when you do

Code:

cin.get();

after outputting the answer, this takes the lf/cr already present and hence your program terminates immediately instead of waiting for your input. You need to clear the input of any characters first, reset any error on input and then get the input.

Re: Why can't I see the output of my C++ code?

Originally Posted by 2kaud

Code:

cin>> c >> n;

will read the two numbers but not the terminating lf/cr. This is still in the buffer. So when you do

Code:

cin.get();

after outputting the answer, this takes the lf/cr already present and hence your program terminates immediately instead of waiting for your input. You need to clear the input of any characters first, reset any error on input and then get the input.

Re: Why can't I see the output of my C++ code?

I am using Dev C++ and I have been told not to use the system("PAUSE") because my antivirus was flagging my code.

Honestly, I didn't know antivirus programs got this sophisticated.

Yes, system("PAUSE") is an easy way for someone to destroy your system. You could download a bogus copy of Dev C++, and in that copy everything is OK, except that there is a "pause.exe" trojan or virus program. So when Dev-C++ automatically creates that "system("pause")" line for you, whenever you run the program, you invoke the trojan/virus.

Re: Why can't I see the output of my C++ code?

Re: Why can't I see the output of my C++ code?

Originally Posted by math8

Thanks for the info, pretty scary in my opinion...

Any C++ IDE that automatically puts "system("pause")" in the code is a candidate for this type of attack. There must be literally thousands of downloads of Dev-C++ (it's old now, so it isn't as popular as it was a few years ago), so this could wreak a lot of havoc on those unfortunate new C++ coders.

I'm a little surprised that the anti-virus people were aware of this -- maybe they got wind of it by a student who had lost a lot of data after running a Dev-C++ generated program.

There was a discussion here some years ago on the "system(pause)" being dangerous, and some (don't remember who now) forum members would advocate its usage because it was "easy" for the beginner student. Well times sure have changed...

Re: Why can't I see the output of my C++ code?

Originally Posted by Paul McKenzie

There was a discussion here some years ago on the "system(pause)" being dangerous, and some (don't remember who now) forum members would advocate its usage because it was "easy" for the beginner student. Well times sure have changed...

However, the possibility of trojanizing the PAUSE command is an urban legend. At least as of XP SP3 and any earlier version of Windows or DOS I know of, it has always been one of the so-called built-in commands. That means it's hard-coded inside the shell (cmd.exe as of XP) and has precedence over any sort oft executable or batch file. Compromizing that command would only be possible by directly manipulating the shell executable itself. So it's not entirely impossible, but much harder than the legend tells.

I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.