பைத்தான் எவ்வாறு C++ நிரல்களின் பிழைகளைக் கையாள்கிறது
பைத்தான் வெற்றிகரமான C++ நிரலை இயக்குவது மட்டுமல்லாது, தொகுத்தலின்
போது C++ கூற்றில் ஏதேனும் பிழைகள் இருப்பின் அவற்றை வெளியிடவும் உதவுகிறது. உதாரணத்திற்கு,
கீழ்க்காணும் C++ நிரலின் ஒரு பிழை உள்ளது. பைத்தான் மூலம் தொகுக்கும் போது என்ன நேரும்
என்பதைப் பார்க்கலாம்.
எடுத்துக்காட்டு 14.8.1
// C++
program to print the message Hello
//Now
select File>New in Notepad and type the C++ program
#include<iostream>
using
namespace std;
int
main()
{
std::cout<<"hello"
return
0;
}
// Save
this file as hello.cpp
#Now select File ->New in Notepad and type the Python program
as main.py
# Program that compiles
and executes a .cpp file
# Python main.py -i hello
import sys, os, getopt
def main(argv):
opts, args =
getopt.getopt(argv, "i:")
for o, a in opts:
if o in "-i":
run(a)
def run(a):
inp_file=a+'.cpp'
exe_file=a+'.exe')
os.system('g++ ' +
inp_file + ' -o ' + exe_file)
Os.system(exe_file)
if_name_=='_main_':
main(sys.argv[1:])
மேற்கண்ட நிரலின் வெளியீடு
C:\Users\Dell>python
c:\pyprg\main.py -i c:\pyprg\ch14\hello
c:\pyprg\hello.cpp: In
function 'int main()':
c:\pyprg\hello.cpp:6:21:
error: expected';' before 'return'
std::cout<<"hello"
˄
;
return 0;
--------------------------
'c:\pyprg\hello.exe' is
not recognized as an internal or external command, operable program or batch
file.
குறிப்பு
மேற்கண்ட
நிரலில், பைத்தான் உள்ள பிழைகளை வெளிக்காட்ட உதவுகிறது. பிழைகள் அவற்றின் வரிசை எண்களுடன்
வெளியிடப்படுகின்றன. அவற்றின் வரிசை எண், பைத்தான் scriptலிருந்து தொடங்குகிறது.