Just started out learning C++

Hello. I'm new to these forums much like I am to C++. I'm likely to have many novice questions, and I apologize in advance for them.

So, I'm just starting out with some beginner code - cout << "Never fear, C++ is here!"; - and I have already encountered what I suspect is a problem.

I'm using Microsoft's Visual Studio compiler and I copied the code exactly as it is shown in my book. When I press "build" it initiates like it is running, but everything closes and nothing happens. When I click Debug it also closes the whole program.

I'm not sure what is happening here. Does anyone have a clue?
closed account (z05DSL3A)
Try going to the menu bar and under the Debug menu select Start without debugging. The likelihood is that the command window closes after your program finishes, Start without debugging will hold the window open so you can see the results.

If this is the problem, read this article :
http://www.cplusplus.com/forum/articles/7312/


PS. Welcome to the forum.
Last edited on
Yeah, that didn't work either. I will read the article, though I'm not sure if I will benefit from it. I'm a newbie, afterall. I'll see what I can glean from it.
Last edited on
closed account (z05DSL3A)
Can you post the full code? If you use the code tags it will be displayed neatly, i.e. type [code], then paste you code, then close the tag with [/code].

Out of interest, what version of VS are you using and what book?
1
2
3
4
5
6
7
8
#include <stdafx.h>
#include <iostream>
using namespace std;

int main() {
	cout << "Never fear, C++ is here!";
	return 0;
}                                                    
Last edited on
you can use system("PAUSE");
before return 0;
Good grief, where do you people come from?
Please system("read the link Grey Wolf posted") before you return 0;
Last edited on
closed account (z05DSL3A)
Pirateshaveparrots,

As masiht, sorry jayt, suggested; you can put the line system("PAUSE"); in your code just before the return 0;. This basically asks the system to run the batch file command 'pause', keeping the window open until it returns from this call. The use of system calls in this manner is generally considered bad practice and not a habit you should get into.

If you did use the Start without debugging menu option and the console window did not stay open, then you have another problem.

I notice that you have #include <stdafx.h> in your code, what type of project did you create?

Please don't instruct people to use system commands! System commands are evil (even though I use them anyway...). Use cin.get(), the user can press enter to exit.
we come from yo momma!, but ya as chrisname said they are evil but who cares i still use them too, but cin.get() works like a champ
If you already know that system is bad then why still use it?
One of my hobbies is pointing out the obvious when I notice everyone else is overlooking it.

Or, since you're already running on debug, you could, you know, set a breakpoint. The default shortcut is F9, IIRC.
I only ever use system() because I have to or if I'm making a Windows-specific app. For example, if I were to 're-write' cmd (which I was going to do, but thought it would be pointless and take too long) using system() commands (which is essentially what cmd does - it passes the parameters you enter to the application you type in, e.g. passing '-s -t 0' to 'shutdown.exe' or similar).
're-write' cmd [...] using system()
Oh, hey, that's a good idea. And it doesn't have "infinite recursion" or "redundant layer" written all over it.
closed account (z05DSL3A)
I'm not even sure I can see why this thread was resurrected.
Oh. Uh... I guess I should have looked at the dates.
closed account (z05DSL3A)
;0)

The comment was more aimed at chrisname...
closed account (S6k9GNh0)

1
2
std::cout << "Please press any button to continue..." << std::endl;
getchar(); //Or std::cin.get() 
Last edited on
Greywolf: - I didn't notice the dates either. It's only 10 days anyway.

Computerquip - The only reason I didn't do that was really for other commands. Can you think how we could have achieved ASSOC? (changes file associations) or shutdown? I mean, you could do system("shutdown"); but then you'd need to have some way for the user to pass their own parameters to the program.

It's "Press any key to continue..." anyway. Can you imagine Microsoft saying please?

You could do this:

cout << "Press any key to continue...";

char i=getch();

switch (i) {

case VK_[key here]:
break;
break;

default:
break;
break;
}

By the way I'm 15 today, and have been for an hour and 45 minutes (it is 1:45 AM here. I'm bored and can't sleep.) Where are my presents, guys?
Last edited on
Topic archived. No new replies allowed.