想运行网上的一段程序,结果编译报错,头文件不存在
#include <stdio.h>
#include <regex.h>
void format_code(char *code) {
// 定义正则表达式用于格式化
const char *pattern = "([{;,]|^)\\s*([a-zA-Z0-9_])";
regex_t regex;
regcomp(®ex, pattern, 0);
regmatch_t pmatch[2];
int status = regexec(®ex, code, 2, pmatch, 0);
if (status == 0) {
// 找到匹配,添加空格
char *formatted = malloc(pmatch[0].rm_eo + 2);
memcpy(formatted, code, pmatch[0].rm_so);
formatted[pmatch[0].rm_so] = ' ';
memcpy(formatted + pmatch[0].rm_so + 1, code + pmatch[0].rm_eo, pmatch[0].rm_eo - pmatch[0].rm_so);
strcpy(code, formatted);
free(formatted);
}
regfree(®ex);
}
int main() {
char code[] = "int main(){int a=10;printf(\"%d\", a);}";
format_code(code);
printf("Formatted code: %s\n", code);
return 0;
}
D:\practice_self\cCodeFormat0422\CCodeFormat.c|2|fatal error: regex.h: No such file or directory|
我选择支持c++11了,因为auto变量可以识别。还是不行。
请问怎么解决呢?