Jump to content
New account registrations are disabed. This website is now an archive. Read more here.
zahraa

C++ Microsoft Visual Studio 2008 FATAL PROBLEM

Recommended Posts

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

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

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 by Foxkit

Share this post


Link to post
Share on other sites

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 by zahraa

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

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 by Foxkit

Share this post


Link to post
Share on other sites

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

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...