-5

I want to translate the following python code in c ++ Can someone help me ??

# -*- coding: utf-8 -*-
print("hello")

fichier = open ('S19.txt','r')
CS_MEF = open ('S19_MEF.txt','w')
ligne = fichier.readline()

i=0
for ligne in fichier:
    id_can = ligne[32]+ligne[33]+ligne[34]+ligne[35]
    if ((id_can == '01A7') or (id_can == '01A8')):

        x = int("0x"+ligne[44]+ligne[45]+ligne[41]+ligne[42],16)
        if x > 0x7FFF:
            x -= 0x10000        
        x = float(x)/17.5
        xd = float(x)*57.29578

        y = int("0x"+ligne[50]+ligne[51]+ligne[47]+ligne[48],16)
        if y > 0x7FFF:
            y -= 0x10000          
        y = float(y)/17.5
        yd = float(y)*57.29578

        z = int("0x"+ligne[56]+ligne[57]+ligne[53]+ligne[54],16)
        if z > 0x7FFF:
            z -= 0x10000          
        z = float(y)/17.5
        zd = float(z)*57.29578

        #print ("0x"+ligne[50]+ligne[51]+ligne[47]+ligne[48])
        chaine = " id ="+ id_can + " x= "+ str(x) + " xd= "+ str(xd) + " y= "+ str(y) + " yd= "+ str(yd) + " z= "+ str(z) + " zd= "+ str(zd) + "\n"
        print (chaine)
        #print ("central tête")
        print(i)
        i = i + 1

        CS_MEF.write( str(i))
        CS_MEF.write(chaine)



print (i)
fichier.close()
CS_MEF.close()
Anas
  • 1
  • 1
  • There are various ways to interface Python with C++, including SWIG, Boost Python, and Cython. To the best of my knowledge, there is no way to automatically convert Python to C++. Also, Pypy may be worth taking a look at. – Faheem Mitha Oct 10 '14 at 10:08
  • 4
    This isn't a great fit for stackoverflow, as you're just asking people to port code to a different language, and people don't tend to like being a code-generation tool. If you have a more specific problem while you're porting it, sure, but not one big code dump. – Yann Oct 10 '14 at 10:26
  • Possible duplicate of [Convert Python program to C/C++ code?](https://stackoverflow.com/q/4650243/608639) – jww Nov 21 '19 at 13:35

1 Answers1

0

You can use Cython. The generated code will still depend on Python libraries though. If your goal is to make the code faster by compiling it Cython will help you accomplish this.

megahallon
  • 144
  • 3