|
-
November 18th, 2002, 05:33 PM
#1
DJGPP Problems
I'm really sorry I have to ask this...
I'm having a hard time Converting from C to C++
I can't seem to get Hello World working.
1 #include <iostream.h>
2
3 int main()
4 {
7 cout << "\n\nHello World!\n";
8 return 0;
9 }
yeah, I\'m gonna need that by friday...

-
November 18th, 2002, 05:38 PM
#2
Your code should read:
Code:
#include <iostream>
using namespace std;
int main()
{
cout << "\n\nHello World!\n";
return 0;
}
Cheers,
cgkanchi
-
November 18th, 2002, 05:38 PM
#3
I just compiled it - and it's just fine. Can you tell me what errors you are getting?
-
November 18th, 2002, 05:45 PM
#4
Here is a screen shot
Thanx for the help, i get this error on multiple computers and multiple versions of Windows...
Edit*
More Madness: I have no trouble compiling C code. Only get errors with C++ source.
yeah, I\'m gonna need that by friday...

-
November 18th, 2002, 05:54 PM
#5
Sorry, I don't think I'm familiar with your compiler. I'm using Microsoft Visual C++ 6.
Just so you can see the the results of your code I've attached a screen shot.
-
November 18th, 2002, 05:56 PM
#6
-Thanx any way gals/guys...
-I guess i'll just stick to C anyway!
-Peace*
yeah, I\'m gonna need that by friday...

-
November 18th, 2002, 07:34 PM
#7
Junior Member
tampabay420: If you use the code that cgkanchi posted, your program will work. You forgot the "using namespace std;" right after your includes. It's a commonly overlooked thing and is not required by all compilers.
HaLCy0n
\"Press any key to continue, or any other key to quit.\"
-
November 18th, 2002, 07:41 PM
#8
Try it like this:
#include <iostream.h>
void main(void)
{
cout << "Hello, World!";
}
I don't think you need the using. . . line with your compiler.
Every now and then, one of you won't annoy me.
-
November 18th, 2002, 07:55 PM
#9
Junior Member
The program that bludgeon posted will work, but I believe that is following the older standards. Let me explain exactly what the using namespace command does.
When you use the standard C++ functions, they are declared in the "std" scope. For example, if I did not put the "using namespace std;" I would have to say something like, "std::cout << "Hello World\n";" in order for it to work. That's just a little explanation.
If you wanna read more indepth about how namespaces work exactly, here's a link for you: http://www.cplusplus.com/doc/tutorial/tut5-2.html
Hope this helps.
HaLCy0n
\"Press any key to continue, or any other key to quit.\"
-
November 18th, 2002, 08:03 PM
#10
I used the using namespace std;
-didn't work... but the link you sent was great. Thanx :-)
edit*
________________________________
#include <iostream>
using namespace std;
int main () {
cout << "Hello world in ANSI-C++\n";
return 0;
}
________________________________
#include <iostream>
int main () {
std::cout << "Hello world in ANSI-C++\n";
return 0;
}
________________________________
Both didn't work, same error... Look at the screen shot...
-Maybe it's my compiler...
yeah, I\'m gonna need that by friday...

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
|
|