I am trying to do console application, that only exits, when user press 'x' ( close ) button, because I want it get working for all the time, until it closes :D. Any idea how to make it? For now I have 'for ( ; ; )' in main function, is it allright, or there are any better way?
int main()
{
// stuff that will execute at start program
while(1)
{
// stuff that will run until 1 will be true (forever), example: if u put cout << "aha" << endl; there, it will cout aha about 1000 times per second
}
}
but I'm not sure this will help you
edit: this will say "starting" on start, and it won't close until you will enter "x" or close with X
themassivechipmunk ? I can't stop laughing, did u wanted to show us how good are u or what? :D he just wanted simple code to keep his application running, not whole class, lul, fail
btw clear function? with 100x "\n" ? are u serious? just wasting of memory, you can use system("cls") instead
stop function - lal? do u know what u did? this will say "stop" like 1000 times per second and it won't stop until u close program :-X
presskey - useless function, we have system("pause") for that
@mekkatorqu: Please follow the rules of this forum and don't bash other users for helping. I should mention that if you would like to offer constructive criticism, you should do so with proper grammar and typing.
@Scottas: Many a user has come to this forum to ask this same type of question. Those ideas are all compiled here: http://cplusplus.com/forum/beginner/1988/ If you read enough there, you might notice system calls are not recommended by more seasoned programmers for various reasons. Hope that page helps your programming :)
@mekkatorqu: Please follow the rules of this forum and don't bash other users for helping. I should mention that if you would like to offer constructive criticism, you should do so with proper grammar and typing.
I think that the jab was warrented, the post that TheMassiveChipmunk wrote was useless and stupid, and nowhere near helpful (c'mon, try some of his examples, they suck). Not to mention the fact that he didn't explain a thing (especially why not to use system () functions or what the hell they even are).
Maybe if you want to act all moderator like, check out chipmunks code and chirp him a little bit for the use of such poor ideas, just throwing the code out with no explanation at all, and the use of non-standard headers (conio.h...).
I personally liked the wait and beep... until I tried to compile and run it... and discovered a sad day when it didn't work :( So now I have no reason to even attempt to defend the code at all.
Or you could just sit in your chair and wait one second and go "Beep", then wait another second and go "Beep", repeating this until someone hits "ENTER" (or just hits). At least this way you can make different tones without writing more code.
Oh sorry no. I was not showing off or anything I was just taught that system was a BAD thing so I thought that would be a good lesson to pass on. Sorry :)
Oh sorry no. I was not showing off or anything I was just taught that system was a BAD thing so I thought that would be a good lesson to pass on. Sorry :)
The reason system is bad is because it is only OS specific.
system () functions are still better than what you posted, at least they work.
Edit:
Isn't getch () platform dependant as well? I know it's non-standard, and I think (not 100% sure) that I read somewhere that it is platform dependant too.
I have read that system was a bad thing but I was in the habit of using it. So it was very hard for me to kick the habit. I thought it would be nice. I am sorry if it came out n00bish.
@kevinkjt2000
The Class Worked well for me are you sure you are not doing anything wrong?
:) http://www.cplusplus.com/forum/beginner/3304/
This is were I read system is bad.
It did compile in my copy of MVSP 2010. It also compiled with other compilers when conio.h was removed, but unfortunately didn't beep in most compiles. Just a sad day, because I like code that makes noise. Using ANSI characters like \a is one of my favorites just to annoy people who run my program.
But I digress the main problem people have with your post is that it wasn't explained at all. It might be bad code practice, but even bad code can look marginally better with awesome documentation.
I have to wonder if Scottas has the problem solved by now because there isn't another post from him.