Welcome Guest ( Log In | Register )

Outline · [ Standard ] · Linear+

 Can't compile, Tried 2 types of compilers

views
     
TScrapp0
post Jan 28 2006, 07:02 PM, updated 20y ago

Look at all my stars!!
*******
Senior Member
4,414 posts

Joined: Feb 2005


I'm starting c++ programming and i've used two compilers which were mentioned in this forum called Microsoft Visual C++ 2005 Express Edition(free) and BloodShed DEV IDE(free) and i can't even compile a simple c++ code such as:

#include<iostream.h>
void main(){
cout<<"Hello";
}

My college computer are using an old version of microsoft visual c++ but i dont know what version they are using and the new microsoft visual c++ 2005 express doesn't even seem to have a button to compile and run the program above which i've saved as a cpp file.
TScrapp0
post Jan 30 2006, 08:25 PM

Look at all my stars!!
*******
Senior Member
4,414 posts

Joined: Feb 2005


Nobody knows?
nasik
post Jan 31 2006, 12:49 AM

⎛⎝⎛ooo..
****
Senior Member
569 posts

Joined: May 2005
From: Bikini Bottom



afaik, building a solution is the way to compile it
TScrapp0
post Jan 31 2006, 01:06 AM

Look at all my stars!!
*******
Senior Member
4,414 posts

Joined: Feb 2005


Is there a compiler which has simple tools like a button to compile and then run my short code with GUI? My college computer has the microsoft c++ compiler which is simple unlike the new microsoft c++ express which doesn't even have a "complie" and "run" button.

sweemeng
post Jan 31 2006, 01:29 AM

organic code generator
*****
Senior Member
879 posts

Joined: Aug 2005
From: kuala lumpur


here is a few lesson in iso c++
lesson 1: standard library do not end with a .h anymore,
library like iostream.h is now iostream,
unless it is non standard library or your own .h file, otherwise it is like above.
also c library is now start with a c. stdlib.h is now cstdlib

lesson 2: void main() is now deprecated, use int main() instead
which must end with a return 0

which explain why dev-c++ not working, because dev-c++ is based on gcc which is based on iso, with some deviation. and vc++ is not what you call standard c++ compiler. so your program might work on vc++,
AaronZe
post Jan 31 2006, 02:47 AM

Getting Started
**
Junior Member
135 posts

Joined: Aug 2005


QUOTE(crapp0 @ Jan 28 2006, 07:02 PM)
I'm starting c++ programming and i've used two compilers which were mentioned in this forum called Microsoft Visual C++ 2005 Express Edition(free) and BloodShed DEV IDE(free) and i can't even compile a simple c++ code such as:

#include<iostream.h>
void main(){
                cout<<"Hello";
}

My college computer are using an old version of microsoft visual c++ but i dont know what version they are using and the new microsoft visual c++ 2005 express doesn't even seem to have a button to compile and run the program above which i've saved as a cpp file.
*
There are some errors in your code, that's why it wont compile...
#include <iostream> must be separated instead of connected. smile.gif

This post has been edited by AaronZe: Jan 31 2006, 02:47 AM
TScrapp0
post Jan 31 2006, 02:56 AM

Look at all my stars!!
*******
Senior Member
4,414 posts

Joined: Feb 2005


How about a compiler which still uses the iostream command with the ".h" in it since i need a compiler which still accepts that command?


nexus-
post Jan 31 2006, 12:23 PM

The intrepid coward
Group Icon
VIP
3,744 posts

Joined: Jan 2003
From: Sydney, Australia



gcc accepts deprecated headers (e.g. ".h" extension headers) with warnings. Have you tried looking at documentation/tutorials on the compilers?
TScrapp0
post Feb 1 2006, 02:10 AM

Look at all my stars!!
*******
Senior Member
4,414 posts

Joined: Feb 2005


QUOTE(nexus- @ Jan 31 2006, 12:23 PM)
gcc accepts deprecated headers (e.g. ".h" extension headers) with warnings. Have you tried looking at documentation/tutorials on the compilers?
*
No but can't it compile just the same? Seems to me that c++ compilers now aren't friendly towards those who are beginners.

My college computers are most probably using an older version of microsoft c++ compiler since it works without any problems whereas the compilers which i've gotten from the net such as gcc can't compile it. I need a compiler which is able to compile in the c++ code in "old school" fashion.
silverhawk
post Feb 1 2006, 11:01 PM

Eyes on Target
Group Icon
Elite
4,956 posts

Joined: Jan 2003


you can include the standard libraries with or without the .h, the difference is in the namespace.

for example
CODE

#include <iostream.h>

void main()
{
    cout << "Hello World" << endl;
}


CODE

#include <iostream>

void main()
{
    std::cout << "Hello World" << std::endl;
}


or a better way... this way you do not need to append the namespace everytime you call a function or something.

CODE

#include <iostream>

using std::cout;
using std::endl;

void main()
{
    cout << "Hello World" << endl;
}

nexus-
post Feb 2 2006, 02:37 PM

The intrepid coward
Group Icon
VIP
3,744 posts

Joined: Jan 2003
From: Sydney, Australia



QUOTE(crapp0 @ Feb 1 2006, 04:10 AM)
No but can't it compile just the same? Seems to me that c++ compilers now aren't friendly towards those who are beginners.

My college computers are most probably using an older version of microsoft c++ compiler since it works without any problems whereas the compilers which i've gotten from the net such as gcc can't compile it. I need a compiler which is able to compile in the c++ code in "old school" fashion.
*
Mainly because gcc is not a C++ compiler? g++ is the GCC (GNU Compiler Collection) C++ compiler, while the actual compiler gcc is the C compiler for GCC. If you are writing pure C code, your "C++" program will still compile though.

This post has been edited by nexus-: Feb 2 2006, 02:38 PM
astalavista_baby
post Feb 5 2006, 02:17 PM

Enthusiast
*****
Senior Member
818 posts

Joined: Jan 2003
QUOTE(crapp0 @ Jan 28 2006, 07:02 PM)
I'm starting c++ programming and i've used two compilers which were mentioned in this forum called Microsoft Visual C++ 2005 Express Edition(free) and BloodShed DEV IDE(free) and i can't even compile a simple c++ code such as:

#include<iostream.h>
void main(){
                cout<<"Hello";
}

My college computer are using an old version of microsoft visual c++ but i dont know what version they are using and the new microsoft visual c++ 2005 express doesn't even seem to have a button to compile and run the program above which i've saved as a cpp file.
*
It would have been better if you could at least give us the compiler error message. Nonetheless, my best bet is the spacing between the #include and the <iostream.h>

Also note that some ANSI compliant C++ compilers nowadays do not accept deprecated header files. Some still do, but with warnings. You could use namespaces instead. If you want to include all functions in the namespace, do this:

CODE

#include <iostream>

using namespace std;


Secondly, we do not normally use void main in C++. I don't know why but some compilers just refuse to compile unless I use int main. So, a corrected version of your code as below should compile just fine. Note that the code has not been tested but it should compile fine:

CODE

#include <iostream>

using namespace std;

int main(){
   cout << "Hello";

   return 0;
}


Don't blame compilers nowadays. No doubt it's a hassle to beginners but it promotes a standard which eventually will promote good programming ethics within programmers. It's good to go through the hassle from the beginning so that you won't find it a hassle later in your programming career. Just my two cents. smile.gif

This post has been edited by astalavista_baby: Feb 5 2006, 02:18 PM
TScrapp0
post Feb 5 2006, 02:49 PM

Look at all my stars!!
*******
Senior Member
4,414 posts

Joined: Feb 2005


Nvm, i've fixed the problem by using microsofts old c++ program which is able to compile the statements which i wanted.
nexus-
post Feb 6 2006, 06:58 AM

The intrepid coward
Group Icon
VIP
3,744 posts

Joined: Jan 2003
From: Sydney, Australia



QUOTE(astalavista_baby @ Feb 5 2006, 04:17 PM)

Secondly, we do not normally use void main in C++. I don't know why but some compilers just refuse to compile unless I use int main.

Don't blame compilers nowadays. No doubt it's a hassle to beginners but it promotes a standard which eventually will promote good programming ethics within programmers. It's good to go through the hassle from the beginning so that you won't find it a hassle later in your programming career. Just my two cents. smile.gif
*
Strict ANSI conforming compilers won't accept void main due to standards imposed, void main is considered poor programming practice as well as return values are important in all programs to indicate the exit status (e.g. successful or did it exit with errors)
astalavista_baby
post Feb 6 2006, 05:14 PM

Enthusiast
*****
Senior Member
818 posts

Joined: Jan 2003
QUOTE(nexus- @ Feb 6 2006, 06:58 AM)
Strict ANSI conforming compilers won't accept void main due to standards imposed, void main is considered poor programming practice as well as return values are important in all programs to indicate the exit status (e.g. successful or did it exit with errors)
*
I guessed as much but wasn't too sure if that was the case. Anyway, thanks for the clarification. smile.gif
dstl1128
post Feb 6 2006, 06:02 PM

Look at all my stars!!
*******
Senior Member
4,464 posts

Joined: Jan 2003
The pre-standard iostream behavior are not supported nor it is compatible to all other C++ compilers. Most recent releases of C++ compiler already drop the backward support of pre-standard stuff, i.e. iostream.h no longer there.

The standard iostream uses template and char_traits heavily, meanwhile the pre-standard (.h) uses common multi-inheritance and non-template approaches... ... ... ... ...

Conclusion - don't use iostream.h



FYI, iostream.h is not deprecated as it was never part of the standard at all.

sinister
post Feb 6 2006, 06:06 PM

Enthusiast
*****
Senior Member
963 posts

Joined: Jan 2003
I don't know what is the error message is , so i can't help you.
lmcckl
post Feb 6 2006, 07:27 PM

Getting Started
**
Junior Member
50 posts

Joined: Dec 2005
From: KL


try borland c++ compiler if it still available, was use as a vc++ alternative for my c++ assignment. ah..good old day biggrin.gif
sinister
post Feb 7 2006, 09:55 AM

Enthusiast
*****
Senior Member
963 posts

Joined: Jan 2003
he he he..

if u have a linux, u can always use GCC
astalavista_baby
post Feb 7 2006, 10:43 AM

Enthusiast
*****
Senior Member
818 posts

Joined: Jan 2003
It's not a matter of compilers, no doubt some compilers are not strict on the standards and will still compile fine but what if the source code is ported to another system? It might not compile. So, it is best to code to the ANSI standard of C++. smile.gif

2 Pages  1 2 >Top
 

Change to:
| Lo-Fi Version
0.0183sec    1.26    5 queries    GZIP Disabled
Time is now: 23rd December 2025 - 11:12 AM