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 }
Printable View
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 }
Your code should read:
Cheers,Code:#include <iostream>
using namespace std;
int main()
{
cout << "\n\nHello World!\n";
return 0;
}
cgkanchi
I just compiled it - and it's just fine. Can you tell me what errors you are getting?
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.
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.
-Thanx any way gals/guys...
-I guess i'll just stick to C anyway!
-Peace*
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.
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.
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.
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...