zahraa 26 Report post Posted August 12, 2013 Hi everybody! I know,I know this site is about game developing not programming languages,But I prefer to come here and ask my question. Well,I wrote a very simple "HelloWorld" program but when i want to start debugging it shows program for about 0.5 sec and then closes it immediately.If i try to start program without debugging it just shows "press any key to continue" instead of output. Also i searched at Google and found many suggestions but they didn't solve my problem I'm really new in C++,So please explain simply. BTW I'm trying to be more active. :) Thank you.SFBE Share this post Link to post Share on other sites
dolarmak 23 Report post Posted August 13, 2013 you'll want to include the code so that others more capable than I can let you know what the problem is. Share this post Link to post Share on other sites
zahraa 26 Report post Posted August 13, 2013 Well,here it is: #include <iostream> using namespace std; int main () { cout << "Hello World!"; return 0; } Share this post Link to post Share on other sites
Foxkit 4 Report post Posted September 10, 2013 (edited) I realize this is almost a month old but here. #include "stdafx.h" #include <iostream> using namespace std; int main () { cout << "Hello World!"; cin.clear(); cin.ignore(255, '\n'); cin.get(); return 0; } That should do it. If not, I'm just dabbling in C++ myself so I'm not sure. I got my source from here: http://www.learncpp.com/ Edited September 10, 2013 by Foxkit 1 zahraa reacted to this Share this post Link to post Share on other sites
zahraa 26 Report post Posted September 10, 2013 (edited) Oh,I totally forgot about it,I can't believe that someone found a solution for this.It worked.Thank you soooooooo much :heart: :heart: :heart: I love you :grin: Do you know why my codes don't work?It's so strange for me...I really need to know why some codes works and some of them don't.I can't see any problem in those codes. I wish I could appreciate you twice :) Edited September 10, 2013 by zahraa Share this post Link to post Share on other sites
Foxkit 4 Report post Posted September 10, 2013 Oh,I totally forgot about it,I can't believe that someone found a solution for this.It worked.Thank you soooooooo much :heart: :heart: :heart: I love you :grin: Do you know why my codes don't work?It's so strange for me...I really need to know why some codes works and some of them don't.I can't see any problem in those codes. I wish I could appreciate you twice :) Your Welcome. I heard something about some compilers closing right away like that. So I did a quick check in my book's faq, turns out your compiler simply doesn't pause after it's done doing it's job so you have to tell it to stop. Also, the #include <stdafx.h> is visual studio specific. I would put it in every time you code from now on. 1 zahraa reacted to this Share this post Link to post Share on other sites
zahraa 26 Report post Posted September 10, 2013 Oh,That's really interesting for me.Could you please tell me exactly which line tells the program to stop?Should I put that line in the end of all programs that I write? Share this post Link to post Share on other sites
Foxkit 4 Report post Posted September 11, 2013 (edited) Oh,That's really interesting for me.Could you please tell me exactly which line tells the program to stop?Should I put that line in the end of all programs that I write? Np, and I would only put it in when your not already telling your program to stop. Such as in when you write a GUI or a command prompt based menu. cin.clear(); cin.ignore(255, '\n'); cin.get(); That entire bit tells it to stop. cin is a command that takes user input(ie. keystrokes) so you theoretically could use just cin.get(); but I'm not 100% certain on that. As far as I can tell, cin.clear() clears any input out and cin.ignore() is telling it to ignore newline commands i believe. It might be the combination of cin.ignore and cin.get that produces the wanted result. You could experiment a little if you wanted. I just don't know off the top of my head unfortunately :oops: . Edited September 11, 2013 by Foxkit 1 zahraa reacted to this Share this post Link to post Share on other sites
zahraa 26 Report post Posted September 11, 2013 Thanks a lot.Of course I'm going to experiment.Maybe when I complete my under developing project.Thanks again for your helps :heart: Share this post Link to post Share on other sites
dolarmak 23 Report post Posted September 11, 2013 Cool to see this was resolved, Thanks fox for helping zahraa. Share this post Link to post Share on other sites
Foxkit 4 Report post Posted September 12, 2013 Cool to see this was resolved, Thanks fox for helping zahraa. Np, just glad I actually could help for once ^^. Share this post Link to post Share on other sites