如何在C ++中检索函数体 [英] how to retrive function body in c++

查看:57
本文介绍了如何在C ++中检索函数体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我有一个函数名,并且我想从文件中获取该函数的主体.
我该如何移动?
例如:

hi all,
i have a function name, and i want to get the body of that function from a file.
how can i move with this?
for eg:

//file.cpp

void xxx()
{
 void main()
 {
  int a,b;
  printf("hi");
 }

 int c=10;
 print(c);
}


如果我给出main(),那么我应该得到main()函数的主体,如下所示


if i give main(),then i should get the body of main() function as follows

{
  int a,b;
  printf("hi);
}


在此先感谢


thanks in advance

推荐答案

如果要通过程序执行此操作,则需要编写一个解析器,该解析器可以扫描文件的文本并识别文件的开头和结尾功能.扫描时,您需要记下所有这些点的位置,以便随后根据需要提取文本.
If you want to do this by program then you need to write a parser that can scan the text of the file and recognise the start and end of functions. As you scan then you need to note the locations of all these points so you can then extract the text as required.


这篇关于如何在C ++中检索函数体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆