simple program error

Hello
I am trying to compile my first program, but it doesn't show the result.
Here is what I did.
On the File menu, point to New, and then click Project….

From the Visual C++ project types, click Win32, and then click Win32 Console Application.

Enter a project name.

By default, the solution that contains the project has the same name as the new project, but you can enter a different name. You can enter a different location for the project if you want.

Click OK to create the new project.

In the Win32 Application Wizard, select Empty Project and click Finish.

If Solution Explorer is not visible, click Solution Explorer on the View menu.

Add a new source file to the project:

Right-click on the Source Files folder in Solution Explorer, point to Add, and click New Item.

Click C++ File (.cpp) from the Code node, enter a file name, and then click Add.

The .cpp file appears in the Source Files folder in Solution Explorer and a tabbed window appears where you type in the code.

Click in the newly created tab in Visual Studio and type a valid C++ program that uses the Standard C++ Library, or copy and paste one of the sample programs.

For example, you can use the set::find (STL Samples) sample program in the Standard Template Library Samples topics in the help.

If you use the sample program for this procedure, notice the using namespace std; directive. This directive allows the program to use cout and endl without requiring fully qualified names (std::cout and std::endl).

On the Build menu, click Build Solution.

The Output window displays information about the compilation progress, such as the location of the build log and a message that indicates the build status.

On the Debug menu, click Start without Debugging.

If you used the sample program, a command window is displayed that shows whether certain integers are found in the set.


I wrote this program in the newly created tab in Visual Studio
// my first program in C++

#include <iostream>
using namespace std;

int main ()
{
cout << "Hello World!";
return 0;
}
First of all, the include file should be iostream.h. But the reason why the program boots out is because you don't have a function telling it to stay on screen. It's working but it only shows for like a millisecond. To fix it you use a function called getch();
@BlueJul. It's iostream, not iostream.h. The .h version is depreciated in most compilers.

@op http://www.cplusplus.com/forum/beginner/1988/
@Zaita: Really? My teacher gave us the really old compiler so i don't know what the newest compilers updated. Do you know where I can download one or do I have to buy those?
Compilers:
http://www.mingw.org - Windows
http://www.gnu.org/software/gcc/ - Linux

If you want an IDE as well
http://www.bloodshed.net/devcpp.html - Windows (Comes with MingW incl)
http://www.eclipse.org - Linux/Windows - Needs compiler
Where should I use getch()
Can you please tell correct this program
// my first program in C++

#include <iostream>
using namespace std;

int main ()
{
cout << "Hello World!";
return 0;
}
@Zaita and BlueJul

My brother told me that when you write .h you dont have to write the using namespace std;
but i dont know why :D
BTW i hope to stay that way.. cuz your explanations are pretty complicated for me xD
@mashiht: http://www.cplusplus.com/forum/beginner/1988/

@hannad: The .h are legacy now and more C-ish. As for writing "using namespace std";. The method if defining a namespace comes down to coding convention.

Alot of people will use "std::cout" and "std::endl" implicitly. Some people use
1
2
using std::cout;
using std::endl;
to restrict the amount of the namespace made available.
@Zaita: Thanks, and now I have to learn what namespace is...

@hannad: Well I learned something new, but .h is so much shorter than using namespace std;

@meshiht: Check the link Zaita gives you, it's actually helpful like you don't have to use getch(); you can use system("Pause"); but experiment, common sense, where do you think it goes. Since Hello World isn't a long program, it won't take long to figure it out.
I forgot to add. Using iostream.h should give you a compiler warning on alot of modern compilers too.

warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.
I did but its not giving anything
It says the application configration is wrong.
Where does system("pause");
go ?
On my system (MSVC2008) - doing an empty project that way creates a configuration
for a GUI program - NOT a console program.

Try changing the configuration like this:

1. Right click the project (not the solution) in the solutions window and select properties.

2. If you select the debug configuration and check Linker->system property you will probably see Windows (/SUBSYSTEM:WINDOWS)

change that to Console (/SUBSYSTEM:CONSOLE) for all configurations
(both debug and release configurations) and see what happens.
// my first program in C++

#include <iostream>
using namespace std;

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

this program is not showing the result at microsoft visual C++ express ??
cout << "Hello World!" << endl;
@ masiht
use the system("PAUSE") function after your cout << "Hello World" << endl;
this will able to to actually see your output before the window closes.
however, dont get into the habit of using system pause. Try to only use it when testing your programs
Topic archived. No new replies allowed.