I am new to programming in C++. I have a bit of experience in Python and ActionScript3. I decided to pick up C++ so I downloaded Dev-C++ complier.

I tried to run the following code but it doesn't seem to do anything. I complied the code, and it did not show any errors. I went to run it and a window appeared really quickly on the screen. It then closed itself after 0.5 seconds. I got the code from cPlusPlus.com.

Do I have to configure a setting or something? I remember when I was working with Python, I had to reconfigure some sort of path directory for Windows.

#include <iostream>
using namespace std;

int main ()
{
  cout << "Hello World!";
  return 0;
}

If you ran it by double clicking the .exe file, then it worked just as it should. The command window opened, displayed the output, then closed.

Try opening a command window, navigate to where the .exe is, then run the program from the command prompt.

I am new to programming in C++. I have a bit of experience in Python and ActionScript3. I decided to pick up C++ so I downloaded Dev-C++ complier.

I tried to run the following code but it doesn't seem to do anything. I complied the code, and it did not show any errors. I went to run it and a window appeared really quickly on the screen. It then closed itself after 0.5 seconds. I got the code from cPlusPlus.com.

Do I have to configure a setting or something? I remember when I was working with Python, I had to reconfigure some sort of path directory for Windows.

#include <iostream>
using namespace std;

int main ()
{
  cout << "Hello World!";
  return 0;
}

Your code is correct. The program will run then immediately disappear when the program is finished, which will happen in the blink of an eye.

http://www.dreamincode.net/forums/showtopic30581.htm

Depending on the IDE you use, the execution window will either stay open or close immediately. I believe on Dev C++, it closes immediately. You can add this line at the bottom to make it pause. Hit "Enter" when done:

cin.get ();

There may be some way within Dev C++ to keep that window open. I believe Visual C++ and Code Blocks keep the window open after completion and Dev C++ does not. I'm not 100% positive.

It has nothing to do with setting a path in Windows. Any setting would be a specific Dev C++ setting. I don't know if such a setting exists.

[EDIT]
Put the line I posted right BEFORE "return 0;", not after.

Thank you.

Is there an IDE that you would recommend a noob that doesn't need me to put in the cin.get (); code?

Thank you.

Is there an IDE that you would recommend a noob that doesn't need me to put in the cin.get (); code?

Microsoft Visual C++ Express Edition (Free) or you can pay for it. But, since you are new, you are no where close to needing to pay for the extra features.....

I have downloaded Microsoft Visual C++ Express Edition and tried using it. I tried to get it to print Hello World with this code but it didn't work.

#include <iostream>
using namespace std;

int main() {
	cout << "hello world";
	return 0;
}

Perhaps my steps to creating a project was incorrect. I went to File, New Project, CLR, CLR Console Application. I then entered a name for my project, aa, and pressed OK. I entered my code, and went to compile it. To compile, I went to Build, Build Solution. It spat out the following error:

1>------ Build started: Project: aa, Configuration: Debug Win32 ------
1>Compiling...
1>aa.cpp
1>.\aa.cpp(1) : warning C4627: '#include <iostream>': skipped when looking for precompiled header use
1>        Add directive to 'stdafx.h' or rebuild precompiled header
1>.\aa.cpp(8) : fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?
1>Build log was saved at "file://c:\Documents and Settings\me\Desktop\aa\aa\Debug\BuildLog.htm"
1>aa - 1 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Create Project | Win32 | select Win32 Console. In the dialog that follows, select Empty Project on the second tab.

I followed your instructions for Microsoft Visual C++ Express Edition and so I have created an Empty Project. There was a blank screen and so there was no where for me to type my code. I then went to File --> New --> File and selected C++ File (.cpp). I then saw a blank screen for me to type my code so I entered in my Hello World program. I went to Build --> Build Solution and again I have the same error.


I tried using Code Block but I can't seem to get the execution window to keep staying up. Can you walk me through how to do this? This is quite frustrating as I just want to learn the language, and it takes so much effort just to get the complier thing working...

I went to File --> New --> File... --> C/C++ source --> Go. I then selected C++ as my language. I entered in a path name, projectA, and placed it on Desktop. I then went Build --> Build, and then Build --> Run. Am I doing this correctly?

I then went to File --> New --> File and selected C++ File (.cpp). I then saw a blank screen for me to type my code so I entered in my Hello World program. I went to Build --> Build Solution and again I have the same error.

It's complaining that you didn't #include "stdafx.h" . This is a typical Microsoft thing and I'm not going to bore you with the details why the good people at Microsoft thought this was necessary.

Here's how to create a project:
- file -> new project
- win32 console application
- type name
- press next
- choose: console application and UNCHECK "precompiled header"
- finish.

I tried using Code Block but I can't seem to get the execution window to keep staying up. Can you walk me through how to do this? This is quite frustrating as I just want to learn the language, and it takes so much effort just to get the complier thing working...

With Code Blocks,

File -> New -> Project -> Console Project -> C++ -> (Pick a Project Name and Path) -> (Click Defaults for Debug/Release and Compiler)

A file called Main.cpp is created for you with the "Hello World" code.

Now select Build -> Build And Run

and you get "Hello World" and the screen stays open! Change the program to whatever you like and hit

Build -> Build And Run

each time to compile and run the program.

I find it frustrating when people ask for help and then don't read the help that they've received only to ask the same question over again...

When you code an application and it reaches it's end it closes. Meaning the terminal window will close and you will not see your message. Therefore, like a few people already suggested you must PAUSE the application via the line: cin.get();

Visual Studio is overkill for someone who is just starting out with hello world type programs. Every programming teacher I've ever had has always told the students not to use a big fancy IDE to learn a language, but to use something simple instead. So, for now forget about visual studio, use Code::Blocks and just add the cin.get() bit at the end of your program (right before the return 0; line). This will allow you to see your output and you won't have to arm wrestle with VS until you've written a few programs and are ready to tackle it. Just my 2 cents worth.

Sorry, I did not mean to sound rude last night. I was just frustrated as I planned to spend yesterday learning C++ but I ended up just trying to set it up :(

Thank you for your help for Microsoft Visual C++ Express Edition, but I think I will take necrolin's advice and use Code Blocks. Anyways, I like the Code Block logo - it reminds me of Google.

I managed to fix my problem. After following VerndonDozier's instructions, it still was not working. I then included the cin.get() line and it still didn't work. I then noticed an error line saying "invalid compiler. Skipping...". After Googling, I came across a thread saying that I need to locate a complier called Ming. I remember that yesterday before using Code Blocks and Microsoft Visual C++ Express Edition I was also using Dev C++ but I had uninstalled it. I decided to install it again and it worked. I am curious as to why I need Dev C++ to make Code Block work?

Code blocks normally defaults to install the compiler with the IDE for you automatically, hassle free. Perhaps you accidentally picked an option to specify your own or not install the compiler or whatever? You're allowed to do that, but it's generally not advisable unless you know what you are doing, and it isn't necessary. If it's still not working, I'd go into the Windows Control Panel and uninstall Dev C++, Code Blocks, and (if it exists separately, the mingw compiler), then reinstall Code Blocks from scratch, being extra careful not to check an option like "don't install compiler" or whatever. I forget the exact install options, but just let Code Blocks install where it wants to and go with all the default options and I think you're fine and it's all automatic.

I think Dev C++ and Code Blocks both use the mingw compiler, but the download for each comes with them. You can download mingw separately, but you don't have to. My hunch is that Code Blocks possibly located the Dev C++ mingw compiler, so it didn't bother to install it, then when you uninstalled Dev C++, that also uninstalled the mingw compiler, so you didn't have a compiler anymore. Again, the most hassle free, surefire way to do this is to uninstall Dev C++, Code Blocks and any copies of mingw that may be left over, then redownload and reinstall Code Blocks from scratch.

There are 2 versions of Code::Blocks. One comes with a compiler and the other one doesn't. VermonDozier is right about Mingw though. Both Code::Blocks and DevC++ use it. However, since DevC++ is an abandoned project that hasn't seen any tender caring love in years the version of Mingw that comes with Code::Blocks will be newer. If you're interested in having the latest Mingw you can always pick it up from their website at: http://www.mingw.org/.

Have fun with your coding. =)

There are 2 versions of Code::Blocks. One comes with a compiler and the other one doesn't.

That makes more sense than my theory, I think. I hadn't ever noticed that there was a version that came without the compiler, but I just visited the download page:

codeblocks-8.02-setup.exe
codeblocks-8.02mingw-setup.exe

NOTE: The codeblocks-8.02mingw-setup.exe file includes the GCC compiler and GDB debugger from MinGW.

The OP probably simply downloaded and installed the first one instead of the second, which is the one he needed.

i think in dev-c++, you can add system("pause"); so you can see the output.

#include <iostream>
using namespace std;
 
int main ()
{
  cout << "Hello World!";
  
  system("pause");
  return 0;
}

i think in dev-c++, you can add system("pause"); so you can see the output.

No. You add cin.get() as suggested multiple times already in this thread.
Here's why you shouldn't use system("pause");

i think add a line of system("pause") would help.. sorry that i am also a newbie ><''

No. You add cin.get() as suggested multiple times already in this thread.
Here's why you shouldn't use system("pause");

Just posted and saw your's..thanks! i understand now ^^''

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.