views:

127

answers:

4

Yes, it's a noob question...

I have been using Dev-C++ for all my projects so far, but it is incredibly outdated, and so where the libraries. So I opened up my copy of Visual C++ and copied the code. When I compile, a million errors pop up, as if every second line of my code is shit. I would hate to start the project again from scratch.

Question: Why is it that Dev-C++ and VC++ compile differently??? I've heard they use different compilers, but its still C++. The first error I looked at was an invalid comparison between a const char* and a std::string.

Anyway, is there any way to make VC++ less strict on programming, as is Dev-C++. Or are there a few major differences between Dec-C++ and VC++ compilers that I should know about.

Most of the errors seem to be std::string related, or LPCWSTR (i can fix that myself).

Sorry about this very broad and useless topic, I'm knew.

-Alex

A: 

Are the project settings the same? Perhaps you need to link in additional .libs or add similar preprocessor directives as you had in Dev-C++. If you just copy and paste the code to a project, you're effectively re-setting the project settings all to default, which for many projects, would break the build.

Apart from that - try adding one of the most common errors you receive to the question, with the line of code, and maybe we can comment.

AshleysBrain
+1  A: 

This will not answer everything, but it might help.

By default, VC++ uses unicode while MinGW (on which DevCpp is based I believe) uses ansi.

This might explain your issues regarding strings: you're basically passing char* strings where most of the functions require something like wchar*.

I suggest that either you fix your code so it becomes unicode compliant, or that you undefine the UNICODE macro in your VC++ project, if unicode is not required.

As you stated, your old code was C++ and the code is C++ as well, so there shouldn't be that much work... as long as you don't rely on compiler specific behaviors.

Could you give us some samples of things that go terribly wrong ? We might be able to help more accurately.

ereOn
skimming over the errors, it appears they are all tied to either std::strings or LPWSTR's. Sigh.... I can make it unicode compliant, but the apparent std::string confusion is troubling. It complained about me assigning one std:string to another!e.g. error C2678: binary '==' : no operator found which takes a left-hand operand of type 'std::string' (or there is no acceptable conversion)
Alexander Rafferty
Great! After changing <string.h> to <string>, all the string errors vanished. The rest are unicode related, should be solved by changing char* to wchar*, and "hi" to L"hi". Things are looking up.
Alexander Rafferty
After changing the charset from unicode to unset, all the errors disappeared, and I was left with only about 20 small fixes I needed to solve. Thanks guys for all the help!
Alexander Rafferty
@Alexander: Indeed, `<string>` is the right way to go. Note that you can also use `std::wstring` instead of `std::string` if you really want make your code unicode compliant. Glad you could solve your issues.
ereOn
A: 

Dev-cpp uses mingw as its compiler. Perhaps you will have more luck using an updated version of mingw, through another IDE. This will help with external dependencies (mingw uses gcc which uses *.a files to link to, VC++ uses *.lib files).

As you mentrion string and LPCWSTR, see ereOn's answer. Make sure you have UNICODE and _UNICODE properly defined (in build flags as -DUNICODE or in VC++ project options).

rubenvb
A: 

First, a few notes, because many Dev-C++ users are confused (I used to be)

Dev-C++ is not a compiler. The compiler is GCC (or, more precisely, a modified version of GCC so that it runs on Windows : MinGW). Dev-C++ is an IDE : a text editor with an additional button which calls MinGW with the appropriate parameters when clicked.

Nothing more.

Same thing for Visual Studio : Visual Studio is the IDE, which calls the Visual Compiler (vc.exe), which implements VC++, which is Microsoft's implementation of the C++ standard.

Second : It's not a noob question. You have discovered portability issues, which is a great area of frustration in C and in C++. A lot of questions on StackOverflow are due to portability problems (a code that works on Windows but not on Linux, etc).

The general rule of thumb is to 1) set your compiler's warning level to the maximum and 2) develop in parallel on all the platforms you're targetting.

Hope this helps.

Calvin1602