#include <iostream>
#include <fstream>
#include <ctime>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <string.h>
using namespace std;
vector< std::string> readtxt_name(string file)
{
ifstream infile;
infile.open(file.data());
cout<<"infile.is_open() is : "<<infile.is_open()<<endl;
if(infile.is_open() ==0){
cout<<"file not existed"<<endl;
}
vector< std::string> txt_name;
string str;
while(getline(infile,str))
{
txt_name.push_back(str);
}
cout<<txt_name.size()<<endl;
infile.close();
return txt_name;
}
int main() {
vector< std::string> txt_name;
vector< std::string> final_path_txt_name;
string path = "/home/data.txt";
std::string str_temp;
char ss[20] ;
txt_name = readtxt_name(path);
for(auto it = txt_name.begin(); it != txt_name.end(); ++it){
str_temp = *it;
strcpy(ss, str_temp.c_str());
string path_final = "/home/";
path_final = path_final + str_temp;
std::cout<<" path_final is: "<<path_final<<std::endl;
final_path_txt_name.push_back(path_final);
}
std::cout << "final_path_txt_name.size is :" <<final_path_txt_name.size()<< std::endl;
return 0;
}
c++ 连续读取某个文件夹下面的多个文件
猜你喜欢
转载自blog.csdn.net/ttomchy/article/details/83275417
今日推荐
周排行