Noob question.. ,

Started by
17 comments, last by pulpfist 14 years, 4 months ago
Turn off precompiled headers. The stadfx thing came up a few times when I was messing with sfml. I assume this is a windows console program? Anyway, turning off precompiled headers should work
C++: Where your friends have access to your private members
Advertisement
I haven't used Microsoft Visual cpp for a while, but I notice the compiler is complaining a lot about stdafx.h. I think there is an option to create a completely blank console project instead of using a precompiled header i.e. stdafx.h (I think it might be a checkbox in the new project dialogue). Try finding this then pasting your code into the new project and recompiling it.

Quote:Original post by Atrix256
What do you have against system("pause"); ?

system("PAUSE"); will only work on Windows, so it isn't portable. Also, the command "pause" just runs a program that waits for input to continue, so there is a possibility that this program can be replaced with malicious code.

I don't think that is very likely but it's still better practice to use something more like:
#include <iostream>#include <string>using namespace std;int main (){cout << "Hello World!" << endl;//system("PAUSE"); Don't use thiscout << "Press enter to terminate the program" << endl;std::string myString;getline(cin, myString);return 0;}


That said, for beginners it's generally fine to use system("PAUSE"); on their own machines until they get the hang of other methods. I'm only a beginner too :)

Hopefully this helps, good luck!

P.S. It's a good idea for you to get into the habit of placing your code in source tags when posting it (see the forum faq). Folk around these parts get cranky if you don't :)

[Edited by - chrisparton1991 on December 4, 2009 7:05:57 PM]
I have a problem with cin.get()... If i have a cin >> VARIABLE right before it, it skips it... I just use system("PAUSE"); for now, but im not doing any complex programs yet... But yeah it always skips te cin.get(); whenever I use it like its not there...
How can a pause be horribly inefficient in speed? I never understood that.
Quote:Original post by MAGIgullorks
I have a problem with cin.get()... If i have a cin >> VARIABLE right before it, it skips it... I just use system("PAUSE"); for now, but im not doing any complex programs yet... But yeah it always skips te cin.get(); whenever I use it like its not there...


I think the reason it skips is because there is a return left in the stream. (The return you pressed earlier doesn't get removed automatically)
You should be able to remove the remaining return using cin.ignore(...), however using cin's operator >> is too low level when reading input from the users, you are better of using getline(cin, ...) instead. The getline function should take care of removing the remaining return as well.
Quote:Original post by CzarKirk
How can a pause be horribly inefficient in speed? I never understood that.


lol

The way I see it using system("PAUSE") is syntactically sluggish. A bit like shooting sparrows with a cannon. It will schedule a new process and it is not portable.
If you'r fine with all that I see no reason not to use it.
Don't pause your program artificially at the end, in any manner. Learn to run it properly, instead. Use a batch script, run it from the command line, set a breakpoint on the last line, whatever is appropriate.

A pause makes for sloppy design because it's an extra step the user has to deal with. It makes it harder to integrate your program with others in batch scripts and looks ugly when the user *is* running the program from the command line (because it's unnecessary and doesn't make sense in context). Of course, none of these things are likely to matter for games, but it's good to take the opportunity to learn good design early.
Quote:Original post by pulpfist
Quote:Original post by CzarKirk
How can a pause be horribly inefficient in speed? I never understood that.


lol

The way I see it using system("PAUSE") is syntactically sluggish. A bit like shooting sparrows with a cannon. It will schedule a new process and it is not portable.
If you'r fine with all that I see no reason not to use it.


The problem with system( "PAUSE" ) is that it is equivalent to opening a console and typing "pause" (try it!) But what if I, as an evil, malicious user created a file with something like
@format c: /quiet
called it "pause.bat" and placed it in the same folder as you're program?

Now, it is highly unlikely that this would actually happen, but it's a good idea to be defensive and there are better solutions to pausing (some of which has already been posted in this thread.)
Quote:Original post by Promethium
Quote:Original post by pulpfist
Quote:Original post by CzarKirk
How can a pause be horribly inefficient in speed? I never understood that.


lol

The way I see it using system("PAUSE") is syntactically sluggish. A bit like shooting sparrows with a cannon. It will schedule a new process and it is not portable.
If you'r fine with all that I see no reason not to use it.


The problem with system( "PAUSE" ) is that it is equivalent to opening a console and typing "pause" (try it!) But what if I, as an evil, malicious user created a file with something like*** Source Snippet Removed ***called it "pause.bat" and placed it in the same folder as you're program?

Now, it is highly unlikely that this would actually happen, but it's a good idea to be defensive and there are better solutions to pausing (some of which has already been posted in this thread.)


drobole@fluxbox:~$ pause-bash: pause: command not founddrobole@fluxbox:~$ 


It's lack of portability saved me(!)

You have a good point though.
Reminds me of the old 'ls' hack from the days when root's PATH still contained the current directory (.) on linux systems

This topic is closed to new replies.

Advertisement