如何写自己的lib文件并测试
1、在VS中新建一个win32工程,建立时选择静态库,如图:
2、也可新建一个win32项目,然后在工程——配置属性——常规中选择,如图:
3、新建一个GetImageName.h文件和一个GetImageName.cpp文件 GetImageName.h文件
#ifndef GET_IMAGE_NAME_H_
#define GET_IMAGE_NAME_H_
#include<io.h>
#include<iostream>
#include<string>
#include<vector>
using namespace std;
void getAllFiles(const string path,const
ext,vector<string>& files);
#endif
GetImageName.cpp文件
#include "GetImageName.h"
void getAllFiles(const string path,const
ext,vector<string>& files)
{
cout<<path<<endl;
cout<<ext<<endl;
//文件句柄
long hFile = 0;
struct _finddata_t fileInfo; string string
string p;
if((hFile =
_findfirst(p.assign(path).append("\\*").append(ext).c_str(),&fileInfo))!=-1)
{
do
{
files.push_back(fileInfo.name);
}while(_findnext(hFile,&fileInfo)==0); _findclose(hFile);
}
}
4、运行,就会在Debug下看到GetImageName.lib
5、测试自己的lib文件,一种方式是将GetImageName.h文件和GetImageName.lib文件放到自己的工程下,另一种是VC++目录下的包含目录和库目录将GetImageName.h文件和GetImageName.lib文件所在的目录添加上,如图
在连接器——输入加上GetImageName.lib,如图
6、测试代码
#include "GetImageName.h"