C++和Matlab最常用的编程技能,实现复杂算法的基础

1、文件读写

(1)获得文件夹下所有的文件

void getFiles(string path, vector<string>& files)
{
//文件句柄  
long   hFile = 0;
//文件信息  
struct _finddata_t fileinfo;
string p;
if ((hFile = _findfirst(p.assign(path).append("\\*").c_str(), &fileinfo)) != -1)
{
do
{
//如果是目录,迭代之  
//如果不是,加入列表  
if ((fileinfo.attrib &  _A_SUBDIR))
{
if (strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0)
getFiles(p.assign(path).append("\\").append(fileinfo.name), files);
}
else
{
files.push_back(p.assign(path).append("\\").append(fileinfo.name));
}
} while (_findnext(hFile, &fileinfo) == 0);
_findclose(hFile);
}
}


(2)读取某个文件的数据

void ReadData(string filepath)
{


ifstream fin(filepath);
string sx,sy,sz;
while (fin >> sx>>sy>>sz)
{

//cout << sx <<" "<< sy <<" "<< sz << endl;
x = atof(sx.c_str());
y = atof(sy.c_str());
z = atof(sz.c_str());
}

}


(3)输出数据到某个文件

void OutputFile()
{
for (int i = 0; i < curvenum; i++)
{


if (curvelist[i].length <=2)
continue;
int point_num_incurve=curvelist[i].point_list.size();
Curve3d curve = curvelist[i];
char outputfilename[300];
sprintf_s(outputfilename, 300, "D:\\CurvesOutput\\x1\\curve%d.off", i);


                //定制文件名

std::ofstream out(outputfilename, std::ios::out);
out << "OFF" << endl;
out << curvelist[i].length << " 0 " << "0 " << endl;



bool isfirst = true;
Point3d point_last;


for (int j = 0; j < point_num_incurve; j++)
{
int pointindex = curve.point_list[j];
Point3d point = pointlist[pointindex];
if (point.valid == 0)
{
continue;
}
out << point.x << " " << point.y << " " << point.z << endl;
}
out.close();
}
}


2、超大矩阵

vector<vector<double>> M1(a1, vector<double>(b1, 0));

建立一个a1*b1的超大矩阵,全部赋值为0,可以非常大


3、基本算法

可以参考我原来写过的算法总结,包括各种基本数据结构的使用等等

点击打开链接



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值