我无法使用python脚本在C代码中添加const关键字。
假设我有一些C代码,例如
<tab><tab>int * a;
我想在其中添加一些const关键字。
<tab><tab>const int *a;
我怎么能得到这个?
我在python中尝试了以下代码
line = "<tab><tab>int * a;"
final_string = "const"+ " " + line
最佳答案
一种方法是使用fileinput
修改文件“就地”
import fileinput
for line in fileinput.input("my_program.cpp",True):
print(line.replace("int* c","const int* c"))
关于python - Python代码在C代码中添加const关键字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54495827/