在头文件中搜索 #ifdef
Searching for #ifdef in a header file
std::string systemStr = "C:\gcc1\gccxml.exe ";
systemStr += """ ;
systemStr += argv[1] ;
std::cout<<"Header File is:"<<argv[1]<<endl;
在上面的代码片段中,argv[1] 表示头文件的名称。我想打开这个头文件并搜索可能存在的 #ifdefs。我该怎么做?问题是 argv[1] 是一个字符串。如果我不清楚,我很抱歉。
这样的事情怎么样...
std::cout<<"Header File is:"<<argv[1]<<endl;
std::ifstream file(argv[1]);
int lineNum = 0;
bool hasIfdef = false;
while( file.good() )
{
std::string line;
std::getline( file, line );
lineNum++;
if( line.find("#ifdef") != std::string::npos ||
line.find("#ifndef") != std::string::npos )
{
std::cout << "Line " << lineNum << ": " << line << std::endl;
hasIfdef = true;
}
}
最简单的方法是使用 shell 脚本:
cat header.h | grep -n "^[:space:]*#[:space:]*if[n]*def"
这将显示行号和 #ifdef 或 #ifndef。
如果您需要从 C 程序中执行此操作,您可以随时执行 shell 脚本。
相关文章:
- 有根的二进制搜索树.保留与其父级的链接
- #ifdef和未声明的标识符
- 在C++中搜索嵌套多映射值
- cpp二进制搜索问题,计算给定数组中输入元素的出现次数
- 二进制搜索树叶数问题
- 为什么二进制搜索在我的测试中不起作用
- 正在尝试重载二进制搜索树分配运算符
- c++binary_search函数排序数组(流行名称搜索)出现问题
- 向量上的线性搜索
- C++ Macros #ifdef
- 如何在动态数组上使用搜索函数
- 对于MacOS上的G++,如何添加默认的include目录/usr/local/include和默认的库搜索路径/usr
- cmake:添加要搜索头文件的目录
- 使用C++创建特殊的二叉搜索树
- 在C++的字符串中搜索和删除某些字符
- std::unordered_map 搜索算法是如何实现的?
- 使用不变量来确定二分搜索中的边界条件
- 二叉搜索如何比线性搜索更快?
- 按边长度递归搜索图中所有可行路径
- 在头文件中搜索 #ifdef