Computer Science Canada

Extreme newbie

Author:  Newguy [ Sat May 03, 2008 3:04 pm ]
Post subject:  Extreme newbie

Ok I am extremely new to C++ and I managed to get my hands on a copy of Visual Basic C++ (the latest version) for free. I created a new project as a "General" prject adn it is empty. Then I added a new item as a .cpp file. Then I entered basic code to display a message as:

Quote:
#include <iostream>
using namespace std;

int main ()
{
cout <<"This is my first C++ program.";
return 0;
}


I can't seem to find the run button to make it work. Should I be looking for a run button. Do I need to enter a command? I have no idea. Right now I compile it (shows it as 1 succeded) and run it by pressing on "Debug". When I do this, the Win32 window shows up, maybe for 1 second, and then quickly disappears. How can I run it or get it to show up constantly. Thanks for answering this extreme newb question. Very Happy

Author:  zylum [ Sat May 03, 2008 3:05 pm ]
Post subject:  RE:Extreme newbie

You need to add a pause before the return.

Author:  Tony [ Sat May 03, 2008 3:10 pm ]
Post subject:  Re: RE:Extreme newbie

zylum @ Sat May 03, 2008 3:05 pm wrote:
You need to add a pause before the return.

That's wrong. And zylum, you should know better Laughing

You need to run the application from the terminal window (command prompt).

Author:  zylum [ Sat May 03, 2008 3:14 pm ]
Post subject:  RE:Extreme newbie

Ehh you're right, that's just me being lazy Laughing

Author:  Kharybdis [ Sat May 03, 2008 3:58 pm ]
Post subject:  Re: Extreme newbie

Build the solution first, then run it without debugging from the debug menu.

Author:  Newguy [ Sat May 03, 2008 7:19 pm ]
Post subject:  Re: RE:Extreme newbie

zylum @ Sat May 03, 2008 3:05 pm wrote:
You need to add a pause before the return.


That is what I am doing right now because I just figured out how to get input from the user.



Tony wrote:

zylum @ Sat May 03, 2008 3:05 pm wrote:
You need to add a pause before the return.

That's wrong. And zylum, you should know better Laughing

You need to run the application from the terminal window (command prompt).


What do you mean by command prompt? I am stupid. Very Happy

Kharybdis wrote:

Build the solution first, then run it without debugging from the debug menu.


Tried building the solution and ran it without debugging from the debug menu but it still quits on me.

Thanks for your help and quick responses. But I still need help. Thanks guys. Smile

Author:  Steven Toews [ Sun May 04, 2008 3:48 am ]
Post subject:  Re: Extreme newbie

Ok so.... Use this to have it say "press any key to continue" system("PAUSE");
Here is the proper code:
#include <iostream>
using namespace std;

int main ()
{
cout <<"This is my first C++ program.";
cout<<endl; // This just drops it down a line to print words
system("PAUSE"); // This pauses the script until a key is pressed
return 0;
}

Author:  Newguy [ Sun May 04, 2008 10:01 am ]
Post subject:  Re: Extreme newbie

Steven Toews @ Sun May 04, 2008 3:48 am wrote:
Ok so.... Use this to have it say "press any key to continue" system("PAUSE");
Here is the proper code:
#include <iostream>
using namespace std;

int main ()
{
cout <<"This is my first C++ program.";
cout<<endl; // This just drops it down a line to print words
system("PAUSE"); // This pauses the script until a key is pressed
return 0;
}


Awesome I will use that. Thanks. Right now I am just doing

int stop;
cin >>stop;
return 0;

Author:  Saad [ Sun May 04, 2008 10:16 am ]
Post subject:  Re: Extreme newbie

Newguy @ Sun May 04, 2008 10:01 am wrote:
Steven Toews @ Sun May 04, 2008 3:48 am wrote:
Ok so.... Use this to have it say "press any key to continue" system("PAUSE");
Here is the proper code:
#include <iostream>
using namespace std;

int main ()
{
cout <<"This is my first C++ program.";
cout<<endl; // This just drops it down a line to print words
system("PAUSE"); // This pauses the script until a key is pressed
return 0;
}


Awesome I will use that. Thanks. Right now I am just doing

int stop;
cin >>stop;
return 0;


Actually, I would not use that. What you have with the cin >> stop is better then system ("PAUSE"). system ("PAUSE") only works with windows, while cin >> stop is cross platform

Author:  Steven Toews [ Sun May 04, 2008 10:22 am ]
Post subject:  Re: Extreme newbie

Sure it's cross platform but it's cheating. You can't just call for a variable everytime you want to pause when a pause function exists...

Author:  Saad [ Sun May 04, 2008 10:25 am ]
Post subject:  Re: Extreme newbie

Steven Toews wrote:

Sure it's cross platform but it's cheating. You can't just call for a variable everytime you want to pause when a pause function exists...


In which case, cin.get() is also there. On another note using the command line is a better alternative

Author:  Steven Toews [ Sun May 04, 2008 10:29 am ]
Post subject:  RE:Extreme newbie

Alright, conclusion reached. If your cross platform developing, or dont want it to say "press any key to continue..." then cin.get() is a greate way to do it. Smile

Author:  Newguy [ Sun May 04, 2008 12:25 pm ]
Post subject:  Re: RE:Extreme newbie

Steven Toews @ Sun May 04, 2008 10:29 am wrote:
Alright, conclusion reached. If your cross platform developing, or dont want it to say "press any key to continue..." then cin.get() is a greate way to do it. Smile


Cool but I am a new person to C++ so I wouldn't worry too much about cross platform development. Smile What do you mean by using the command line?

Author:  Tony [ Sun May 04, 2008 12:56 pm ]
Post subject:  Re: RE:Extreme newbie

Newguy @ Sun May 04, 2008 12:25 pm wrote:
I wouldn't worry too much about cross platform development.

You should.

The command prompt is the terminal window you get when you go to Start -> run -> cmd

Author:  Newguy [ Sun May 04, 2008 1:21 pm ]
Post subject:  Re: RE:Extreme newbie

Tony @ Sun May 04, 2008 12:56 pm wrote:
Newguy @ Sun May 04, 2008 12:25 pm wrote:
I wouldn't worry too much about cross platform development.

You should.

The command prompt is the terminal window you get when you go to Start -> run -> cmd

I know what the command prompt is I don't know what he meant by "using the command line"

Author:  Tony [ Sun May 04, 2008 1:26 pm ]
Post subject:  RE:Extreme newbie

he meant that using the command prompt is a preferred way to starting your program

code:

cd "C:/path/to/app folder"
./app_name.exe


Since this is the type of an application you are developing.

Author:  Steven Toews [ Sun May 04, 2008 6:31 pm ]
Post subject:  RE:Extreme newbie

He meant run theprogram while inside of the command prompt.. example: run>>cmd>>cd desktop/ >> programname.exe

Author:  Newguy [ Sun May 04, 2008 7:55 pm ]
Post subject:  Re: RE:Extreme newbie

Steven Toews @ Sun May 04, 2008 6:31 pm wrote:
He meant run theprogram while inside of the command prompt.. example: run>>cmd>>cd desktop/ >> programname.exe

No I know how to run the program inside command prompt I just didn't know if he meant C++'s command line window at the bottom or command prompt. Also I tried running it through command prompt and it still closes but it doesn't close when I use system ("PAUSE") which means it is going on to return 0; and quiting. Therefore I guess it was a problem with my code. If you think not than please tell me what else is wrong. Smile

On a side note. Very good and useful forum here and the members seem to be very helpful. Very Happy

Also on another side note. Razz Do any computer classes after grade 10 teach C++? Is it school dependant? Do ALL schools teach Java?

Author:  Tony [ Sun May 04, 2008 8:11 pm ]
Post subject:  RE:Extreme newbie

What should happen is that you open the command prompt, run the application, have it print the output, finish, exit. The command prompt should remain open. If your application is closing the otherwise open terminal, you are doing something wrong.

On your unrelated note -- it is school dependent. Some schools don't teach upper year CS at all.


: