how to convert C# to C++ [closed]

▼魔方 西西 提交于 2019-12-04 02:08:12

Actually as it is complicated to mix C# and C++ on unix, I am trying to convert C# to C++

Have you considered Mono? It is something that's definitely worth checking before starting to learn C++ in order convert and run an existing .NET application on Unix. It's also binary compatible meaning that you don't even need to recompile your existing assembly.

Learn C#, learn C++, and spend a lot of time rewriting.

Or use PInvoke from the C# assembly to call into a C++ dll.

Or write managed C++ and compile with the /clr switch. The resulting assembly can be referenced and used from C# projects.

Reed Copsey

It is nearly impossible to directly translate C# to C++ so that it will run on Unix machines.

This is mainly due to the fact that the .NET Framework is not available (from C++) on Unix machines. Mono will allow you to run many C#/.NET programs, but does not support C++/CLI (the C++ extensions that allow directly working with the .NET Framework).

Converting the language is possible - though difficult due to differences in approach (e.g., garbage collection in C#), but the framework calls will require porting to different libraries, and it is often not a good candidate for a direct translation.

For example, in your code above, you'd have to decide on a C++ library for web access - and once you had that choice made, it would dictate the code required to call into that library to download the website string.

I'm using C# to C++ converter time to time. It's really great for snippet conversion from c# to c++ or c++/cli.

Consider looking at Vala. Vala is a C#-like language that converts into C and then into an executable. There are very little differences with C#. You will still have to use your brain though.

You may want to consider CoreRT. It's a .NET project whose goal is to eliminate the need for the CLR to be present on the target platform for running an application. Instead, it generates C++ code from a given C# code. That C++ code is compiled and linked on any target platform that supports C++.

A post on a Microsoft blog said: "If I really want to write some C# code and have it 'just work' on a new IoT device, I don’t have any options until the RyuJIT is capable of generating machine code that works with that processor and operating system." By cross-compiling C# to C++, .Net developers can then deliver their applications without needing to wait for .Net to be deployed on a given platform.

https://github.com/dotnet/corert

Edit:
The site listed has been discontinued. I'll leave the old answer here for reference ...

Old answer:
Here is an online converter that will automate the process for you! ...

Varycode online converter

It can do C# to C++ and back again as well as converters for Ruby, Python, Java & VB, apparently!

Edit:
It appears to have had its C++ (and java) functionality removed - it says temporarily, but has done so for a long time now. Hopefully they'll resurrect it soon!
Still works for some other languages (VB, Ruby, Python, Boo).

Here is the website where you can find C# to C++ converter.

https://github.com/ASDAlexander77/cs2cpp

You just need to perform some steps to generate and compile C++ code from C#. Additionally this application converts C# code into C++ which is cross platform compatible.

As already mentioned here, the translation of libraries can be an issue, but one open source project that might help at some cases is:

http://alexalbala.github.io/Alter-Native/

Citation from its main page:

It provides a tool to easy port applications from high-level languages such as .NET to native languages like C++. It is a research project and it is under development with the collaboration of UPC - BarcelonaTech and AlterAid S.L.

   static void Main(string[] args)
    {
        int t = int.Parse(Console.ReadLine());
        for (int i = 0; i < t; i++)
        {
            string []a = Console.ReadLine().Split();
            string[] b = Console.ReadLine().Split();
            int n = int.Parse(a[0]);
            int k = int.Parse(a[1]);
            int c = int.MinValue;
            for (int l = 0; k<=n; l++)
            {
                for (int j = l; j < k; j++)
                {
                    if (int.Parse(b[j]) > c)
                        c = int.Parse(b[j]);
                }
                k++;
                Console.Write(c);
                c = int.MinValue;
            }
        }
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!