读取文件内容生成对应的文件夹

C语言 码拜 8年前 (2016-02-01) 1078次浏览
读取文件内容生成对应的文件夹
图中的内容为一个TXT文件内的,需要创建的文件夹的结构,,本人现在是想要读取该TXT文件内容,然后根据里面内容生成对应的多层文件夹,刚学C 各种不懂!
解决方案:80分
#include<iostream>
#include<iomanip> 
#include<fstream>
#include<string>
using namespace std;
int main()
{
	char buffer[256] = {0};
	string original_path = "e:";
	string path_name[5] = {"", "", "", "", ""};//创建一个string数组用来存放每层文件夹的名字,假定最多只有5层
	ifstream myfile ("e:\data.txt");
	if(!myfile)
		cout << "Unable to open myfile";  
	else
	{
		while (!myfile.eof())  
		{  
			string cur_path = "md " + original_path;
			myfile.getline(buffer,10);
			string data(buffer);
			for(int i = 0; i < 10; i++)
			{
				if(data[i] != ""\t"")
				{
					path_name[i] = data.substr(i);
					cur_path = cur_path + "\" + path_name[i];
					break;
				}
				cur_path = cur_path + "\" + path_name[i];
			}
			cout << cur_path << endl;
			system(cur_path.c_str());
		}  
	}
	system("pause");
}

读取文件内容生成对应的文件夹


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明读取文件内容生成对应的文件夹
喜欢 (0)
[1034331897@qq.com]
分享 (0)