0

i found a translator for c++ to c# , but it doesn't work. (Code2Code.net)

Test with cout

int main(int argc, char** argv)
{
cout << "Hello World";
return 0;
}

The Results becomes

public static int Main(string [] argv) 
{ 
cout << "Hello World"; 
return 0; 
} 

My Question to you, is = is it any other translator that works for C++ to C# (dont need to be free)

4

4 回答 4

7

I am not aware of any as this kind of translation would be very difficult to do. You are trying to translate code that was written in an unmanaged language into a language that is managed. Even if you were able to translate the code you would have almost every method marked as unsafe which would negate most of the benefits of moving to C# in the first place.

This seems like a bad idea - you ought to be thinking about rewriting the application from scratch.

于 2009-02-16T16:05:18.817 回答
6

My suggestions would be to initially use C++/CLI to port over the C++ code to a managed environment. Once working in the managed world, build new code in C# around it. If there are key areas of the existing code that are actively changing, consider porting to C# at that point.

于 2009-02-16T16:18:07.227 回答
0

I don't think any translation engine for C++ -> C# could do more than safe a bit of typing on boilerplate code (fix basic syntax) - as the frameworks used in C++ and C# are fundamentally different, and you will run into problems as soon as the translator has to deal with pointers arithmetics and stuff like this.

Given the complex syntax of C++ and the crazy stuff you can do with it (think Boost) I guess any translator would run into serious trouble sooner or later. See this blog post for some alternative suggestions.

于 2009-02-16T16:11:46.867 回答
0

Code2Code.net 明确声明

您接受此页面只完成了一半的工作。

...

在大多数情况下,翻译后的代码甚至无法编译。

于 2009-02-17T19:38:46.003 回答