0

i have write a basic code in c++

#include <iostream>
using namespace std;
void main()
{
    cout <<"its my programm";
}

when i compile it cmd line appear for a second and terminated noting was display. its was showing me this output in debug window.

'while.exe': Loaded 'C:\Windows\SysWOW64\kernel32.dll'
'while.exe': Loaded 'C:\Windows\SysWOW64\KernelBase.dll'
'while.exe': Loaded 'C:\Windows\winsxs\x86_microsoft.vc90.debugcrt_1fc8b3b9a1e18e3b_9.0.30729.1_none_bb1f6aa1308c35eb\msvcp90d.dll'
'while.exe': Loaded 'C:\Windows\winsxs\x86_microsoft.vc90.debugcrt_1fc8b3b9a1e18e3b_9.0.30729.1_none_bb1f6aa1308c35eb\msvcr90d.dll'
The program '[1480] while.exe: Native' has exited with code 0 (0x0).

help me regarding this .

Bibi Tahira
  • 1,062
  • 5
  • 14
  • 39
  • 5
    You forgot to ask a question. Your debug output appears perfectly correct. Your output appeared in your program's console, but when your program ended, so did its console. – David Schwartz May 19 '12 at 07:04
  • 3
    Your main is not valid. It must return `int`. – user703016 May 19 '12 at 07:05
  • @Cicada: MS Visual C++ accepts `void` as the return type of the `main` function. – Mohammad Dehghan May 19 '12 at 07:23
  • @MD.Unicorn That's not standard, it's a Microsoft Extension. – user703016 May 19 '12 at 07:28
  • 3
    Hence the `visual-c++` tag, I guess. In any case, that's one of Microsoft's _lesser_ crimes against the standard :-) – paxdiablo May 19 '12 at 07:30
  • possible duplicate of [Why is the console window closing immediately without displaying my output?](http://stackoverflow.com/questions/8868338/why-is-the-console-window-closing-immediately-without-displaying-my-output) – Cody Gray May 19 '12 at 07:50

3 Answers3

1
#include <iostream>
using namespace std
int main() {
    cout << "Hello World";
    cin.get();
    return 0;
}

This should work. The console exits before you can view the program. Using cin.get() will keep the program running until you press enter.

On a related note, your main() function really should be int and not void. I'm pretty sure some compilers do not allow void main().

Ayrx
  • 1,942
  • 4
  • 24
  • 33
0

That's because your console closes before you can see the output.

Try stepping through your program with F10. Or place a locking statement before the return.

Also, not that main should return int.

Luchian Grigore
  • 245,575
  • 61
  • 446
  • 609
0

Try this:

#include <iostream>
using namespace std;
void main()
{
    cout <<"its my programm";
    cin.get();
}

Then you must hit the Enter to close the console window.

Mohammad Dehghan
  • 17,154
  • 3
  • 54
  • 67