我的程序遇到了一个奇怪的错误:头文件减慢了程序的速度。我用空代码(即 : main() {}
)测试头文件,运行该空代码需要 40 秒。
头文件 .h
#include "stdafx.h"
#include <string>
#ifndef LZ_H
#define LZ_H
extern int e,i;
extern std::string dic[1000000];
void init();
#endif
函数文件 .cpp
#include "lz.h"
#include "stdafx.h"
#include <string>
std::string dic[1000000];
int i=0;
int e=0;
std::string cstr(char c)
{
return std::string(1,c);
}
void init()
{
for (e=0;e<=255;e++) dic[e]=cstr(e);
e=e-1;
}
测试主文件 .cpp
#include "lz.h"
void main() {}
结果:40 秒。我以前从未遇到过如此奇怪的错误。