Question:
Not working hello world c++?
2011-03-20 23:24:59 UTC
this is the code
1: #include
2:
3: int main()
4: {
5: cout << "Hello World!\n";
6: return 0;
7: }

im using visual C++ compiler and i keep getting an error message cannot find iostream.h also when i get other code to run it runs for like 2 seconds and then the command prompt window vanishes im just learning so please don't use massive words that a beginner wont be able to understand im reading learning c++ in 21 days
Eight answers:
Shadow Wolf
2011-03-21 01:00:05 UTC
C++ assumes header files end in .h so just take that out. Visual C++ probably didn't include .h on any of thier compiler header files.



The rest of the code looks like a textbook example so it should be fine. I'll save the lecture for no args on a console program.



Because you are using Windows, it closes the command window as soon as the program finishes. The correct way to run a command line program is manually open a window navigate to the file location and execute it from the command line. In the start menu of WinXP and later it is usually labeled "Command Prompt" but if you are using something really old like Win98 or earlier it is called a DOS window. Enter help for a command list and further instructions on using help.



The next problem is which version of Visual C++? You could have an incompatibility problem a configuration problem or both. You might want to take a look at how things are configured and do some manual tweaking. Of importance here is whether the compiler knows where the header files are. You can change this in most IDE's. You could also try a re-install with the custom option and watch how it is installed. At the very least, you may have to figure out where the header files are installed.



What operating system? The answer makes a difference to what advice I can give. If you are using a 32 bit operating system, then you have a lot of free options other than Visual C++. You can run any 16 or 32 bit compiler. If you are using a 64 bit operating system, you may not be able to run 16 bit programs without some extra software. Download DOSbox to run 16 bit programs. Since you probably won't be creating any GUI programs, you may want to consider some command line compilers other than VC++. Go to http://cprogramming.com for some more compilers. I'd suggest DJGPP and RHIDE though you may have some fits getting your system configured to run it. The reason for this mess is DJGPP creates 32 bit programs with 16 bit headers. You also have the option of using Linux and doing your work there with gcc and various Linux tools.



Last is a bit of advice. Don't assume you are a programmer after 21 days. I keep a couple of the 21 days type books for reference so I know more or less what is in yours. Once you get through the book, that is just a small beginning because the book is only really teaching you the programming language. You still need to learn how to use the programming language. It all takes months and even years.



Shadow Wolf
?
2011-03-20 23:32:20 UTC
In Akash C++ Follow these Steps:



1. Select A New Project.



2. Select ‘Empty Project’.



3. Go to File->New->Source File or press Ctrl-N and click ‘Yes’ in the dialog.



4. Enter the code.











#include



using namespace std;







int main()



{



cout << “Hello World!” << endl;



return 0;



}



Use this code I am definitely sure it will work.

*If the screen pops up and disappears very fast then add the line ‘cin.ignore()’ after the cout. (this happens in Akash C++)*



Make sure you type it in exactly as it appears with the correct cases or it won’t compile.



Use this code I am definitely sure it will work.
Andy T
2011-03-20 23:57:20 UTC
For the vanishing part, simple: program flow ended, program ends, Windows assuming whatever it was you were doing with those program is done; so based on that assumption close the window.



Not quite sure how to fix it besides do the running command in a cmd window you open by yourself; that way Windows won't be able to assume anything nor close it. Leave the Visual C++ strictly for compiling.
Brent
2016-08-01 17:23:22 UTC
I find the best way to keep the command prompt window from vanishing is to add a breakpoint at the end of the program. In this case you could put it on either line 6 or line 7. Place the insertion point there and then press F9.
Farzam
2011-03-21 00:42:40 UTC
if you're not going to put



using namespace std;



between the #include and the int main(), you need to put



std::



before each cout that you use.
2011-03-20 23:28:20 UTC
first line of code should be



#include
Jousha
2016-09-19 17:05:53 UTC
it's probably not " #include " but rather try " #include " and try having to use the stdio header file as well.
Ramandeep
2011-03-21 03:42:49 UTC
try using eclipse wascana as c++ ide

youcan get it at



http://eclipselabs.org/p/wascana


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...