1.读取一个文件夹下固定格式的文件名,并改名为序号开头的文件
#include <string>
#include <vector>
#include <fstream>
#include <windows.h>
#include <iostream>
#include <io.h>
#include <sstream>
using namespace std;
void getFiles(string path, string exd, vector<string>& files)
{
long hFile = 0;
struct _finddata_t fileinfo;
string pathName, exdName;
if (0 != strcmp(exd.c_str(), ""))
{
exdName = "\\*." + exd;
}
else
{
exdName = "\\*";
}
if ((hFile = _findfirst(pathName.assign(path).append(exdName).c_str(), &fileinfo)) != -1)
{
do
{
if ((fileinfo.attrib & _A_SUBDIR))
{
if (strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0)
getFiles(pathName.assign(path).append("\\").append(fileinfo.name), exd, files);
}
else
{
if (strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0)
files.push_back((fileinfo.name));
}
} while (_findnext(hFile, &fileinfo) == 0);
_findclose(hFile);
}
}
void main(){
string filePath, extraName;
cout << "filepath:" << endl;
cin >> filePath;
cout << "extra name:" << endl;
cin >> extraName;
vector<string> files;
getFiles(filePath, extraName, files);
char str[30];
int size = files.size();
for (int i = 0; i < size; i++)
{
std::stringstream sstream;
std::string Name;
string newName;
string newFileName, oldFileName;
sstream << i;
sstream >> Name;
newName = Name.append(".").append(extraName);
std::cout << files[i] << endl;
oldFileName = filePath + ("\\") + (files[i]);
newFileName = filePath + ("\\") + (newName);
if (rename(oldFileName.c_str(), newFileName.c_str()) == 0)
{
printf(" 改名成功完成!!");
}
}
system("pause");
}
2.从obj模型文件中读取顶点生成点晕(可用来从文件中读入参数)
#include <pcl/visualization/cloud_viewer.h>
#include <pcl/io/io.h>
#include <pcl/io/pcd_io.h>
#include <pcl/io/ply_io.h>
#include <pcl/common/common.h>
#include <iostream>
int main()
{
ifstream inf;
inf.open(".\\all\\Merged mesh.obj");
pcl::PointCloud<pcl::PointXYZRGB>::Ptr m_cloud(new pcl::PointCloud<pcl::PointXYZRGB>);
std::string s, s1, s2, s3, s4;
while (std::getline(inf, s))
{
std::istringstream in(s);
in >> s1 >> s2 >> s3 >> s4;
if (s[0] == 'v')
{
if (s[1] != 'n'&&s[1] != 't')
{
pcl::PointXYZRGB point3D;
point3D.x = (float)atof(s2.c_str());
point3D.y = -(float)atof(s4.c_str());
point3D.z = (float)atof(s3.c_str());
point3D.r = 0;
point3D.g = 0;
point3D.b = 0;
m_cloud->push_back(point3D);
}
}
}
return 0;
}