|
-
Jul 30th, 2002, 07:36 PM
#1
Thread Starter
Fanatic Member
Hello world NOT WORKING?! (solved)
ok, heres the code, im sure uve all seen it b4...
#include <iostream>
int main()
{
std::cout << "Hello World!\n";
return 0;
}
When i run the program... nothing happens... isn't it supposed to display hello world to my screen???
(simplest program and i can't get it right )
It was just the window disppearing before i could even see it, thanks
Last edited by alkatran; Jul 31st, 2002 at 04:02 PM.
Don't pay attention to this signature, it's contradictory.
-
Jul 30th, 2002, 08:41 PM
#2
Addicted Member
either you have to use iostream.h or if you are using iostream
you have to write
using namespace std...
-
Jul 30th, 2002, 09:00 PM
#3
Frenzied Member
Code:
#include <iostream>
int main()
{
cout << "Hello World!\n";
return 0;
}
try removing the
std::
and use the code above
Being educated does not make you intelligent.
Need a weekend getaway??? Come Visit
-
Jul 30th, 2002, 09:26 PM
#4
PowerPoster
If you mean that the screen just closes after about a second, try taking some input before closing like this:
PHP Code:
#include <iostream>
int main()
{
int i;
cout << "Hello World!\n";
cin>>i;
return 0;
}
-
Jul 30th, 2002, 11:02 PM
#5
Frenzied Member
When you #include <iostream>, you must either include the line "using namespace std;", the lines "using std::<object here>;", or prefix all standard object names with "std::". Here is the hello world program with all three options:
Code:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World!\n";
return 0;
}
Code:
#include <iostream>
using std::cout;
int main()
{
cout << "Hello World!\n";
return 0;
}
Code:
#include <iostream>
int main()
{
std::cout << "Hello World!\n";
return 0;
}
abdul is also correct. If the window simply flashes on and off screen again, try adding an input call like he did.
Z.
-
Aug 2nd, 2002, 01:58 PM
#6
Fanatic Member
also, try flushing the buffer.
cout << "blah"; will stay in the buffer untill you flush the buffer into the screen. you have to use endl to flush the buffer or the function flush.
try:
PHP Code:
#include <iostream>
int main()
{
std::cout << "Hello World!" << endl;
return 0;
}
Notice the endl to finish the line, it does more than just add a '\n' at the end. It also flushes the buffer.
Regards,
MoMad
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|