how to convert C# to C++

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.


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.


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.

Tags:

C#

C++

Mixing