views:

297

answers:

5

I need to work with some old C++ code that was developed in Visual C++ 6.0. Right now it's giving me compile errors galore. (For instance, "cannot open include file: 'iostream.h'"... because now it should say #include <iostream> rather than #include <iostream.h>).

How can I work with this code without having to change it all over the place?

+8  A: 

Unfortunately, there isn't a targetting feature in VS2008 that lets you do this.

You'll just need to clean up your code. Luckily, VS2008 is far more standards-compliant than older versions of Visual C++ (in particular, VC 6). Getting the code clean should help in the future (you're less likely to have to worry about this later), as well as help if you ever decide to port to other platforms.

Reed Copsey
+15  A: 

Problem is, VC6 was very very broken. You only got away with those compiler errors in vc6 because vc6 was so loose. Fix the errors, you'll be glad that you did-- I've done that conversion twice, and it makes the code much safer.

mmr
+4  A: 

As others have mentioned, improving the code to work with VS 2008 will be a worthwhile exercise.

If that is not an option (i.e., the legacy app broke and a fix is needed immediately) you could try creating a virtual machine with VC 6 installed and using that to compile the application.

Michael
Good call on the VM.
Kyle Ryan
There's no reason to install VC6 in a VM - it coexists quite nicely with subsequent versions of Visual Studio.
Michael Burr
+2  A: 

If you're looking for a swich that will essentially force Visual Studio 2005/2008 to use the VC6 compiler for C++ code, it doesn't exist.

There are ways to do it with custom make files and lots of hackery. I don't know anyone who's achieved this but I'm sure it's possible with enough work.

However, I agree with most of the other people on this thread. You'd be much better served by fixing the code now. You'll likely spend as much time or more implementing a work around as you would just fixing the code straight up.

JaredPar
+1  A: 

You should definitely fix the code.

If you cannot do it, and if you have only issues like #include<iostream.h> you can also create an iostream.h file yourself:

#pragma once

#pragma message("*********************************************")
#pragma message("Do not use #include <iostream.h> in new code!")
#pragma message("*********************************************")

#include <iostream>

using namespace std;
Cristian Adam