compiling Borland

Techy Geek

Daemon Poster
Messages
1,320
I have been tryin to learn C++, I got a tutorial and tried this code
Code:
// my first program in C++
#include <iostream.h>
int main <>
{
cout << "hello world!"; >>
return 0;
}

NB that was written by my IT teacher (so was the tutorial) and i am pretty sure that its right
anyway, I am trying to compile it and it comes up with this message:
error E2209 hiworld.cpp 2: Unable to open include file "iostream.h"
Error E2141 hiworld.cpp 3: Declaration syntax error
*** 2 errors in Compile ***
what should I do to get the darn thing to compile, is the code wrong (I'd dearly love the tell the IT teacher he got it wrong, that would be great!!!) or is it something else
Another note, I have to put the BCC32.exe file into the folder from which i am compiling, otherwise it doesnt work but I am completely stuck, please help
 
// my first program in C++
#include <iostream.h>
int main <>
{
cout << "hello world!"; >>
return 0;
}


In the first line: #include <iostream.h> Remove the ".h" so it reads: #include <iosteam>

Also replace the <> in: int main<>, with () so it reads: int main().

Then get rid of the >> after "Hello World!"

Last but not least but a "/n" after the "!" but before the quotes like this: cout << "Hello World!/n";

What "/n" does is it moves the cursor down a line so that when Hello World! appears it isn't followed directly with Press any key to continue. Instead "Press any key to continue." would appear below Hello World. It just makes it easier to read. If you dont understand what I mean then run the program first without the "/n" and then run it with it in so that you see what I mean.

You also need to add: using namespace std;
below #include <iostream>

So finished with those adjustments your code should look like this:
Code:
#include <iostream>
using namespace std;
int main()
{
	cout << "Hello World!\n";
	return 0;
}

Happy Programming. If you need help you can post again, PM, email, or IM me.

Also, what compiler are you using?
 
Starr said:
Also, what compiler are you using?

borland C++, the actual program I link it to in cmd is bcc32, it still doesnt work however, the new problems are:
error E2209 hiworld.cpp 1 : Unable to open include file "iostream"
Error E2282 hiworld.cpp 2 : Namespace name expected
Error E2451 hiworld.cpp 5 : Undefined aymbol "cout" in function main ()
*** 3 Errors in Compile ***

please help, any is welcome
 
I suggest you forget all about Borland C++ - it's so old, the legends say Julius Caesar learnt programming on it.

Try Dev C++ - it's what I use - it's bang up to date, free, and you can download addons to program virtually anything in it. It's brilliant - there's no need to buy anything more expensive like MS Visual Studio.

Your code should look like this:

Code:
#include <iostream>

int main()
{
std::cout<<"Hello World!\n";
return 0;
}

Or, you can do:

Code:
#include <iostream>

using namespace std;

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

Hope this helps. Let us know if you have further problems (I'll be out of the loop for about 10 days).
 
http://lab.msdn.microsoft.com/express/visualc/default.aspx

^^^^^
Get that. It is free. Dev C++ you have to write extra code so you can see the output with this you won't. Just click Build -> Build Solution then Debug -> Start without debugging.

Also get in the habbit of using the second code malbuc posted.

"using namespace std;" will save you a lot of typng when you start doing bigger projects.
 
Starr said:
http://lab.msdn.microsoft.com/express/visualc/default.aspx

^^^^^
Get that. It is free. Dev C++ you have to write extra code so you can see the output with this you won't. Just click Build -> Build Solution then Debug -> Start without debugging.

Also get in the habbit of using the second code malbuc posted.

"using namespace std;" will save you a lot of typng when you start doing bigger projects.

Yay for digging up old articles, NO I WILL NOT LET SUCH BLASPHEMY LIVE. Visual Studios C++ (Pre 7.1) is not C++, it is more like... "Visual C++ programming" kinda like how "Turbo C++ programming" was. Dev-C++ use standard, (New national standard, which 7.1 uses is the GCC way to compile). You could also use for more efficent coding.

Code:
#include <iostream>
using std::cout;
using std::endl;
int main(void)
{
    cout << "Hello world, mansecks?"<<endl;
    return 0;
}

Instead of using a namespace for everything that is defined in iostream, which causes more bog on your ram... (after setting up a few namespaces, you start to understand why).
 
Back
Top Bottom