1.对文件夹下所有图片进行处理:
#include <io.h>
#include <opencv2/opencv.hpp>
string fileFolderPath = "...";//目录
string fileExtention = "bmp";
string fileFolder = fileFolderPath + "\\*." + fileExtention ;
char fileName[1000];
struct _finddata_t fileInfo;
long findResult = _findfirst(fileFolder.c_str(), &fileInfo);
if(findResult != -1)
{
sprintf(fileName, "%s\\%s", fileFolderPath.c_str(), fileInfo.name);
//对第一幅图进行处理...
}
while(!_findnext(findResult, &fileInfo))
{
sprintf(fileName, "%s\\%s", fileFolderPath.c_str(), fileInfo.name);
//对下一幅图进行处理...
}
//释放源图
_findclose(fileResult);
2、向txt文件写入数据:
#include <fstream>
#include <iostream>
ofstream in;
in.open("xxx.txt", ios::app);
in << ...<< "\n";
说明:
ios::app ---添加到文件尾;
ios::ate---把文件标志放在末尾,而非起始;
ios::trunc---默认,截断并覆盖原来内容。
3.带默认形参的函数:应该把有默认值的形参都放在右边!
4.c++结构体定义:
struct Student
{
int a;
};//定义了结构体类型Student,声明变量时:Student stu1;
struct Student
{
int a;
}stu2;//stu2是一个变量,使用时可以直接访问:stu2.a;
typedef struct Student
{
int a;
}stu3;//stu3是一个结构体类型,使用时必须先:stu3 lh;再lh.a = 10;