c++学习杂项

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;




  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值