主题:菜鸟求救
#include <stdio.h>
#include <io.h>
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
using namespace std;
const char *to_search="c:\\zpt\\ahma\\*.*";
const string path="c:\\zpt\\ahma\\";
int main()
{
long handle;
struct _finddata_t fileinfo;
vector<string> name;
string str;
string buf;
handle = _findfirst(to_search, &fileinfo);
if (handle == -1)
{
return -1;
}
printf("%s\n", fileinfo.name);
name.push_back(path+fileinfo.name);
while(!_findnext(handle, &fileinfo))
{
printf("%s\n", fileinfo.name);
name.push_back(path+fileinfo.name);
}
_findclose(handle);
vector<string>::const_iterator it = name.begin();
it++;
it++;
ifstream infile;
ofstream outfile;
outfile.open("c:\\ahma.txt");
buf="";
while(it!=name.end())
{
infile.open(it->c_str());
while(getline(infile,str))
{
buf+=str+'\n';
}
infile.close();
infile.clear();
it++;
}
outfile<<buf;
outfile.close();
return 0;
}
我做论文,这个程序是把我的一个文件夹里的单个zpt数据读出来存在一起,这个程序是老师给的。发现里面好多不懂,跪求大虾们帮忙分析下,小弟在此谢过......
#include <io.h>
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
using namespace std;
const char *to_search="c:\\zpt\\ahma\\*.*";
const string path="c:\\zpt\\ahma\\";
int main()
{
long handle;
struct _finddata_t fileinfo;
vector<string> name;
string str;
string buf;
handle = _findfirst(to_search, &fileinfo);
if (handle == -1)
{
return -1;
}
printf("%s\n", fileinfo.name);
name.push_back(path+fileinfo.name);
while(!_findnext(handle, &fileinfo))
{
printf("%s\n", fileinfo.name);
name.push_back(path+fileinfo.name);
}
_findclose(handle);
vector<string>::const_iterator it = name.begin();
it++;
it++;
ifstream infile;
ofstream outfile;
outfile.open("c:\\ahma.txt");
buf="";
while(it!=name.end())
{
infile.open(it->c_str());
while(getline(infile,str))
{
buf+=str+'\n';
}
infile.close();
infile.clear();
it++;
}
outfile<<buf;
outfile.close();
return 0;
}
我做论文,这个程序是把我的一个文件夹里的单个zpt数据读出来存在一起,这个程序是老师给的。发现里面好多不懂,跪求大虾们帮忙分析下,小弟在此谢过......