自己尝试了一些代码
#include<io.h>
#include<iostream>
#include<fstream>
#include<vector>
#include<string.h>
#include<string>
using namespace std;
//int fileread(string dir,vector<string>filename)
//{
//
//}
int main()
{
ifstream infile;
ofstream outfile;
int i = 0; //保存文件数量
struct _finddata_t fileinfo;
long fHandle;
string fileName[80];
//string dir;
cout << "请输入文件路径" << endl;
//cin >> dir;
//vector<string>fileName; //保存文件名
if ((fHandle = _findfirst("E:\\multifile\\*.txt", &fileinfo)) == -1L)
{
cout << "当前目录下无文件" << endl;
return 0;
}
else
{
do
{
fileName[i] = fileinfo.name;
i++;
} while (_findnext(fHandle, &fileinfo) == 0);
}
/*for (int j = 0; j < i; j++)
{
cout << fileName[j] << endl;
}*/
for (int j = 0; j < i; j++)
{
infile.open("E:\\multifile\\fileName[i]")
}
return 0;
}
在45行处怎么修改可以实现呢?因为在引号里面那个fileName[i]的话就会识别为字符串饿了
test.exe * 不一定支持中文路径
#include <fstream>
#include <iostream>
int main(int argc, char *argv[])
{
std::ifstream test;
char a;
for (int i = 1; i != argc; ++i)
{
test.open(argv[i]);
test >> a;
std::cout << a << std::endl;
test.close();
}
return 0;
}
c++17添加了头文件filesystem,有相关操作,否则就自己封装每个平台上的平台函数