文件管理系统_文件管理系统
生活随笔
收集整理的這篇文章主要介紹了
文件管理系统_文件管理系统
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
運行截圖:
代碼:
/*Header.h*/ #pragma once #define _CRT_SECURE_NO_DEPRECATE #include<iostream> #include<direct.h> #include<io.h> #include<cstring> #include<string> #include<string.h> #include<fstream> #include <conio.h> //包含_getch()函數 #include <algorithm>//包含字符大小寫轉換函數transform() #include<Windows.h> #include<stdio.h>using namespace std;/************************************************ //系統中用到的一些全局變量 *************************************************/bool SystemOpen = false;//判斷文件系統是否已經打開string UInfoPath = "C:FileSystemUInformation.txt";//記錄用戶信息的文件路徑/*用戶信息*/ struct User {string Username="";string Password=""; };User user[8]; //創建八個用戶對象/*臨時使用的用戶結構體*/ struct Temp {char Username[20];char Password[20]; }TempUser;/*當前系統的信息*/ string Username = "";//記錄當前用戶名 string Uname="";//用于行首標記 string SPath="";//記錄當前根目錄的路徑 string newpath = "";//用于記錄運行時的新路徑 int changepathnum = 0;//記錄用戶改變路徑的次數,判斷是否要加‘/’/*文件操作對象和變量*/ fstream finout; const char* filepath;//記錄文件路徑 const char* openfilepath;//記錄處于打開狀態的文件的路徑 string Ofilepath; FILE *fp; long totalfilebyte = 0;//下面的變量用于格式化系統或者刪除目錄樹 string to_search = "C:/FileSystem"; string path = "C:/FileSystem"; int index = 0;//用于標記字符串 int FEindex;//記錄開始循環時文件夾的個數 int LEindex;//記錄循環結束時文件夾的個數 string record[100];//記錄要刪除的文件夾所在的路徑/*枚舉變量*/ enum EnumType{CH,CLOSE,CREAT,DELECT,DIR,FORMAT,HELP,LOGIN,LOGOUT,MKDIR,OPEN,QUIT,RD,READ,WRITE};/*用于和選擇的操作進行對比*/ string operation[15] = { "CH","CLOSE","CREAT","DELETE","DIR","FORMAT", "HELP","LOGIN","LOGOUT","MKDIR","OPEN","QUIT","RD","READ","WRITE" };/*實現系統功能函數用到的函數聲明*/ int select(string selection); string HidPwd(int i); void mkdirs(string muldir); void AddUInfo(string FilePath, User user); void ReadUInfo(string FilePath, Temp tempuser); void menu(); void DDRF(); void NewSystem();/*系統的功能函數*/ void ch1(string changepath); void close1(); void creat1(string filename); void del1(string filename); void dir1(); int format1(); void help1(); void login1(); void logout1(); void mkdir1(string str); void open1(string filename); void quit1(); void rd1(string str); void read1(); void write1();/*FileSystem.cpp*/ #include"Header.h" using namespace std;EnumType choice; string getstr; string selection; string str; int choicenum; int i = 0;void getoperation(string getstr);//該函數用于讀取操作名稱及參數int main() {NewSystem();if (SystemOpen){menu();cout << SPath << "> ";cin.clear();cin.sync();getline(cin, getstr);getoperation(getstr);while (true){if (choicenum == 11){if (str != ""){cout << "無效輸入!" << endl;cout << SPath << "> ";getline(cin, getstr);getoperation(getstr);}else{break;}}/*必須登錄以后才能夠執行的操作*/while (Uname==""&&str!="-help"&&str!="-HELP"&&choicenum != 5 && choicenum != 7&&choicenum!=-1){cout << "請先登錄!" << endl;cout << SPath << "> ";getline(cin, getstr);getoperation(getstr);}/*根據輸入選擇操作*/switch (choicenum){case -1: {cout << "無效輸入!" << endl; break; }case 0: {if (str == "-help" || str == "-HELP"){cout << "CH 改變文件目錄" << endl;cout << "CH [foldername]/[foldername]/.../[foldername]" << endl;cout << "如果用戶目錄下有文件夾file1,file1內有文件夾file2" << endl;cout << "打開file2目錄的語句必須為:CH file1/file2" << endl;cout << "CH root (返回根目錄)" << endl << endl;}else if(str!=""){ch1(str);}else{cout << "無效輸入!" << endl;}break; }case 1: {if (str == "-help" || str == "-HELP"){cout << "CLOSE 關閉已打開的文件" << endl;cout << "CLOSE 無參數" << endl << endl;}else if(str==""){close1();}else{cout << "無效輸入!" << endl;}break;}case 2: {if (str == "-help" || str == "-HELP"){cout << "CREAT 在當前目錄下創建文件" << endl;cout << "CREAT filename" << endl << endl;}else if(str!=""){creat1(str);}else{cout << "無效輸入!" << endl;}break;}case 3: {if (str == "-help" || str == "-HELP"){cout << "DELETE 指定路徑下的文件" << endl;cout << "DELETE [foldername]/.../[foldername]/filename" << endl << endl;}else if(str!=""){del1(str);}else{cout << "無效輸入!" << endl;}break;}case 4: {if (str == "-help" || str == "-HELP"){cout << "DIR 列出當前目錄下的所有文件名" << endl;cout << "DIR 無參數" << endl << endl;}else if (str == ""){dir1();}else{cout << "無效輸入!" << endl;}break;}case 5: {if (str == "-help" || str == "-HELP"){cout << "FORMAT 格式化文件系統,刪除系統內的全部文件和用戶信息" << endl;cout << "FORMAT 無參數" << endl << endl;}else if (str == ""){if (format1() == 1){}else{NewSystem();}}else{cout << "無效輸入!" << endl;}break;}case 6: {if (str == "-help" || str == "-HELP"){cout << "HELP 顯示系統中指令的信息" << endl;cout << "HELP 無參數" << endl << endl;}else if (str == ""){help1();}else{cout << "無效輸入!" << endl;}break;}case 7:{if (str == "-help" || str == "-HELP"){cout << "LOGIN 用戶登錄" << endl;cout << "LOGIN 無參數" << endl << endl;}else if (str == ""){login1();}else{cout << "無效輸入!" << endl;}break;}case 8:{if (str == "-help" || str == "-HELP"){cout << "LOGOUT 退出當前用戶" << endl;cout << "LOGOUT 無參數" << endl << endl;}else if (str == ""){logout1();}else{cout << "無效輸入!" << endl;}break;}case 9: {if (str == "-help" || str == "-HELP"){cout << "MKDIR 在當前目錄下創建新的目錄" << endl;cout << "MKDIR [foldername]/../[foldername]" << endl << endl;}else if (str != ""){mkdir1(str);}else{cout << "無效輸入!" << endl;}break;}case 10: {if (str == "-help" || str == "-HELP"){cout << "OPEN 打開當前目錄下的一個文件" << endl;cout << "OPEN filename" << endl << endl;}else if (str != ""){open1(str);}else{cout << "無效輸入!" << endl;}break;}case 12: {if (str == "-help" || str == "-HELP"){cout << "RD 刪除目錄樹" << endl;cout << "RD [foldername]/../[foldername]" << endl;cout << "如果用戶目錄下有文件夾file1,file1內有文件夾file2" << endl;cout << "刪除file2目錄樹的語句必須為:RD file1/file2" << endl << endl;}else if (str != ""){rd1(str);}else{cout << "無效輸入!" << endl;}break;}case 13: {if (str == "-help" || str == "-HELP"){cout << "READ 讀取當前已打開的文件內容并顯示" << endl;cout << "READ 無參數" << endl << endl;}else if (str == ""){read1();}else{cout << "無效輸入!" << endl;}break;}case 14: {if (str == "-help" || str == "-HELP"){cout << "WRITE 向已打開的文件末尾寫入新的內容" << endl;cout << "WRITE " << endl << endl;}else if (str == ""){write1();}else{cout << "無效輸入!" << endl;}break;}}/*用戶登錄后的行首內容*/if (Uname != ""){cout << Uname<<"> ";}/*用戶未登錄時的行首內容*/else{cout << SPath << "> ";}cin.clear();cin.sync();getline(cin, getstr);getoperation(getstr);}quit1();}return 0; }void getoperation(string getstr) {int i=0;/*該循環用于判斷是否有空格(即有無參數)*/for (i;; i++){if (getstr[i] == ' ' && (i + 1) != getstr.length()){break;}else if (getstr.length() == (i + 1)){break;}else continue;}/*如果沒有空格,則整個getstr當作操作名稱*/if (getstr.length() == (i + 1)){selection = getstr;str = "";choicenum = select(selection);}/*如果有空格,空格前面部分為操作名稱,后面為參數*/else{selection = getstr.substr(0, i);str = getstr.substr(i + 1, getstr.length() - i);choicenum = select(selection);} }/***************************************** //實現系統功能函數用到的函數 *******************************************//*用于判斷選擇的操作*/ int select(string selection) {int i;int choicenum;for (i = 0; i < 15; i++){transform(selection.begin(), selection.end(), selection.begin(), ::toupper);if (selection == operation[i]){choicenum = i;break;}}if (i == 15){choicenum = -1;}return choicenum;}/*用*號隱藏輸入的密碼*/ string HidPwd(int i) {string pwd;char temp_pwd;if (i != 0){temp_pwd = _getch();}while (true){temp_pwd = _getch();if (temp_pwd == 13){break;}if (temp_pwd == 0){continue;}if (temp_pwd == 8){cout << "b" << " " << "b";pwd.pop_back();continue;}cout << '*';pwd.push_back(temp_pwd);}cout << endl;return pwd; }/*新建文件夾*/ void mkdirs(string muldir) {int i;int len;char str[512];strcpy_s(str, muldir.c_str());len = strlen(str);for (i = 0; i < len; i++){if (str[i] == '/'){str[i] = '0';if (_access(str, 0) != 0){_mkdir(str);}str[i] = '/';}}if (len > 0 && _access(str, 0) != 0){_mkdir(str);}}/*記錄新的用戶信息,保存到 UInformation.txt*/ void AddUInfo(string FilePath, User user) {strcpy_s(TempUser.Username, user.Username.data());strcpy_s(TempUser.Password, user.Password.data());ofstream fout;fout.open(FilePath, ios_base::out | ios_base::app | ios_base::binary);if (fout.is_open()){fout.write((char*)&TempUser, sizeof TempUser);fout.close();}else{cout << "Failed to record user's information!";cin.get();}}/*打開系統時讀取用戶信息*/ void ReadUInfo(string FilePath, Temp tempuser) {ifstream fin;int i = 0;fin.open(FilePath, ios_base::in | ios_base::binary);if (fin.is_open()){while (fin.read((char*)&tempuser, sizeof tempuser)){user[i].Username = tempuser.Username;user[i].Password = tempuser.Password;i++;}fin.close();}else{cout << "Failed to read users' information!";cin.get();}}/*指令幫助菜單*/ void menu() {cout << "有關某個命令的詳細信息,請鍵入 命令名 -HELP" << endl;cout << "CHt" << "改變文件目錄" << endl;cout << "CLOSEt" << "關閉文件" << endl;cout << "CREATt" << "創建文件" << endl;cout << "DELETEt" << "刪除文件" << endl;cout << "DIRt" << "列文件目錄" << endl;cout << "FORMATt" << "格式化文件系統" << endl;cout << "HELPt" << "提供文件系統的幫助信息" << endl;cout << "LOGINt" << "用戶登錄" << endl;cout << "LOGOUTt" << "退出當前用戶" << endl;cout << "MKDIRt" << "創建目錄" << endl;cout << "OPENt" << "打開文件" << endl;cout << "QUITt" << "退出文件系統" << endl;cout << "RDt" << "刪除目錄樹" << endl;cout << "READt" << "讀文件" << endl;cout << "WRITEt" << "寫文件" << endl;cout << endl; }/*用于查找目錄下的文件夾路徑并保存到字符串數組中,和刪除目錄下的文件*/ void DDRF() {long handle;//用于查找的句柄struct _finddata_t fileinfo;//文件信息的結構體path = path + "/*";handle = _findfirst(path.data(), &fileinfo);//第一次查找if (-1 == handle){return;}if (!_findnext(handle, &fileinfo))//除去父目錄的影響{}while (!_findnext(handle, &fileinfo))//循環查找符合條件的文件{if (fileinfo.attrib&_A_SUBDIR)//文件夾{record[index] = to_search + "/" + fileinfo.name;index++;}else//文件{string newpath = to_search + "/" + fileinfo.name;remove(newpath.data());//刪除文件}}_findclose(handle);//關閉句柄 }/*打開現有文件系統或者新建文件系統*/ void NewSystem() {string choose;bool unfinish = true;//用于記錄創建系統的操作是否完成if (SystemOpen)//用于格式化以后使用{ofstream fout;fout.open(UInfoPath.data(), ios_base::out);fout.close();}else{/*判斷是否存在一個文件系統,若不存在則新建一個*/if (_access("C:/FileSystem", 0) != 0){cout << "是否新建一個文件系統?(Y/N):";getline(cin, choose);while (unfinish){/*新建一個文件系統*/if (choose == "Y" || choose == "y"){_mkdir("C:/FileSystem");SystemOpen = true;SPath = "C:/FileSystem";ofstream fout;fout.open(UInfoPath.data(), ios_base::out);fout.close();unfinish = !unfinish;}/*不新建文件系統*/else if (choose == "N" || choose == "n"){unfinish = !unfinish;}/*輸入的選擇有誤*/else{cin.clear();cin.sync();cout << "輸入有誤,請重新輸入:";getline(cin, choose);}}}/*已有文件系統,詢問是否直接打開*/else{cout << "是否打開現有的文件系統?(Y/N):";getline(cin, choose);while (unfinish){/*打開現有的文件系統*/if (choose == "Y" || choose == "y"){SystemOpen = true;cout << "已打開現有的文件系統!" << endl << endl;SPath = "C:/FileSystem";ReadUInfo(UInfoPath, TempUser);unfinish = !unfinish;}/*不打開現有的文件系統*/else if (choose == "N" || choose == "n"){unfinish = !unfinish;}/*輸入的選擇有誤*/else{cin.clear();cin.sync();cout << "輸入有誤,請重新輸入:";getline(cin, choose);}}}cout << endl;}}/************************************************** //系統的功能函數 **************************************************//*改變文件目錄*/ void ch1(string changepath) {if (changepath == "root" || changepath == "ROOT"){newpath = SPath;Uname = "[" + Username + "] ";changepathnum = 0;}else{path = SPath + "/" + changepath;struct stat s;if (stat(path.data(), &s) == 0)//判斷路徑是否存在{if (s.st_mode&S_IFDIR)//是文件夾{if (changepathnum == 0){Uname = Uname + changepath;changepathnum = 1;}else{Uname = "[" + Username + "] " + changepath;}newpath = path;}else//文件{cout << "請輸入目錄名!" << endl;}}else{cout << "路徑錯誤!" << endl;}} }/*關閉文件*/ void close1() {if (finout.is_open()){openfilepath = "";Ofilepath = "";cout << "文件關閉成功!" << endl;}else{cout << "無打開的文件" << endl;} }/*創建文件,先判斷該文件是否存在,存在則詢問是否覆蓋,不存在則直接新建文件*/ void creat1(string filename) {ofstream fout;string fpath = newpath + "/" + filename;/*文件已存在*/if (_access(fpath.data(), 0) == 0){cout << "文件已存在,是否要覆蓋該文件?(Y/N):";char choose;bool unfinish = true;while (unfinish){cin >> choose;cin.get();/*覆蓋文件*/if (choose == 'Y' || choose == 'y'){fout.open(fpath, ios_base::out);fout.close();unfinish = false;cout << "創建文件成功!" << endl;}/*放棄覆蓋文件*/else if (choose == 'N' || choose == 'n'){unfinish = false;cout << "創建文件失敗!" << endl;}/*輸入有誤,提示重新輸入*/else{cout << "文件已存在,是否要覆蓋該文件?(Y/N):";}}}/*文件不存在,則創建新文件*/else{fout.open(fpath, ios_base::out);fout.close();cout << "創建文件成功!" << endl;} }/*刪除文件*/ void del1(string filename) {string fpath;fpath = newpath + "/" + filename;/*查看文件是否在當前目錄下*/if (_access(fpath.data(), 0) == 0){if (remove(fpath.data()) == 0){cout << "刪除文件成功!" << endl;}else{cout << "刪除文件失敗!" << endl;}}else{cout << "該文件不在當前目錄下!" << endl;} }/*列文件目錄*/ void dir1() {int filenum = 0;int foldernum = 0;string path = newpath + "/*";long handle;//用于查找的句柄struct _finddata_t fileinfo;//文件信息的結構體handle = _findfirst(path.data(), &fileinfo);//第一次查找if (handle == -1){cout << "路徑有誤!" << endl;}if (!_findnext(handle, &fileinfo))//除去父目錄的影響{}while (!_findnext(handle, &fileinfo))//循環查找符合條件的文件{if (fileinfo.attrib&_A_SUBDIR)//文件夾{cout << "<DIR>" << 't' << 't' << fileinfo.name << endl;foldernum++;}else//文件{totalfilebyte = totalfilebyte + fileinfo.size;cout << "<FILE>" << 't' << 't' << fileinfo.name<< 't' << 't' << fileinfo.size << endl;filenum++;}}cout << 't' << filenum << " 個文件" << 't' << 't' << totalfilebyte / 8 << "字節" << endl;cout << 't' << foldernum << " 個目錄" << 't' << 't' << endl;cout << endl; }/*格式化文件系統,調用DDRF刪除目錄下的所有文件,并刪除字符串數組中記錄的文件夾。*/ /*用戶無調用該函數的權力*/ int format1() {bool unfinish = true;if (Uname != ""){cout << "用戶無權利格式化系統!" << endl;return 1;}cout << "格式化系統將刪除系統內所有的文件以及用戶信息,確定格式化?(Y/N):";char choose;cin >> choose;cin.get();while (unfinish){if (choose == 'y' || choose == 'Y'){DDRF();LEindex = index;FEindex = LEindex;if (LEindex == 0)//沒有文件夾{}else//存在文件夾{for (int j = 0; j < FEindex; j++)//第二次查文件夾并記錄新的文件夾和刪除文件{to_search = record[j];path = record[j];DDRF();}LEindex = index;while (LEindex > FEindex)//有新增文件夾路徑,則繼續往下記錄新的文件夾和刪除文件{for (int j = FEindex; j < LEindex; j++){to_search = record[j];path = record[j];DDRF();}FEindex = LEindex;LEindex = index;}for (int j = FEindex; j >= 0; j--)//從最新記錄的文件夾開始刪除,并置相應字符串為空{RemoveDirectory(record[j].data());record[j] = "";}}cout << "格式化系統成功!" << endl << endl;/*重置記錄數為0,以供下一次使用*/index = 0;FEindex = 0;LEindex = 0;string to_search = "C:/FileSystem";string path = "C:/FileSystem";for (int i = 0; i < 8; i++){user[i].Username = "";user[i].Password = "";}unfinish = !unfinish;}else if (choose == 'n' || choose == 'N'){cout << "取消格式化系統!" << endl << endl;unfinish = !unfinish;}else{cout << "輸入錯誤,請重新輸入:";cin >> choose;cin.get();}return 0;} }/*顯示指令信息*/ void help1() {menu(); }/*用戶登錄:用戶名存在,輸入密碼登錄;用戶名不存在,提示是否要創建新用戶;用戶數目已滿,再有新的用戶名稱出現,則直接提示該用戶不存在 */ void login1() {if (Uname != "")//判斷是否已有用戶登錄{cout << "請先退出當前用戶再進行登錄操作!" << endl;}else{string username;string password;cout << "Username:";getline(cin, username);int i = 0;for (i; i < 8; i++){/*如果輸入的用戶名不存在,且還有空用戶,則詢問是否要創建新用戶*/if (user[i].Username.empty() && user[i].Username.compare(username) != 0){char choose;cout << "Passwords:";cin.clear();cin.sync();password = HidPwd(0);cout << "是否創建新用戶?(Y/N):";cin >> choose;bool unfinish = true;while (unfinish){/*創建新用戶*/if ((choose == 'Y' || choose == 'y') && cin.get() == 'n'){user[i].Username = username;user[i].Password = password;AddUInfo(UInfoPath, user[i]);Username = user[i].Username;Uname = "[" + user[i].Username + "] ";SPath = SPath + "/" + "Users/" + user[i].Username;newpath = SPath;mkdirs(SPath);unfinish = !unfinish;cout << "創建新用戶成功!" << endl;}/*不創建新用戶*/else if ((choose == 'N' || choose == 'n') && cin.get() == 'n'){cout << "創建新用戶失敗!" << endl;unfinish = !unfinish;}/*輸入錯誤*/else{cout << "輸入有誤,請重新輸入:";while (cin.get() != 'n')continue;cin >> choose;}}break;}/*如果輸入的用戶名存在,則請用戶輸入密碼進行登錄*/else if (user[i].Username.compare(username) == 0){int j = 0;//用于函數HidPwd()cout << "Passwords:";cin.clear();cin.sync();password = HidPwd(j);j++;/*3次密碼錯誤,則提示登錄失敗!*/for (j; j < 4; j++){if (user[i].Password.compare(password) == 0){Username = user[i].Username;Uname = "[" + user[i].Username + "] ";SPath = SPath + "/" + "Users/" + user[i].Username;newpath = SPath;cout << "登錄成功" << endl;break;}else{cout << "密碼錯誤,請重新輸入!" << endl;cout << "Passwords:";password = HidPwd(j);}}if (j == 4){cout << "登錄失敗!" << endl;}break;}else{}}/*如果空用戶數為0,則無法創建新用戶,直接提示用戶不存在*/if (i == 8){cout << "該用戶不存在,且無法新建用戶!" << endl;}} }/*無用戶處于登錄狀態,返回警告提示;否則,退出當前用戶*/ void logout1() {if (Uname == ""){cout << "無效操作!" << endl;}else{Username = "";Uname = "";newpath = "";changepathnum = 0;if (finout.is_open()){finout.close();}SPath = "C:/FileSystem";cout << endl;} }/*創建目錄*/ //改好了 void mkdir1(string str) {string path = newpath + "/" + str;if (_access(path.data(), 0) == 0)//目錄已存在{cout << "目錄已存在!" << endl;}else{mkdirs(path);if (_access(path.data(), 0) == 0){cout << "創建目錄成功!" << endl;}else{cout << "創建目錄失敗!" << endl;}} }/*打開文件,先判斷文件是否存在,再打開文件*/ void open1(string filename) {if (finout.is_open()){cout << "請先關閉當前文件!" << endl;}else{string fpath = newpath + "/" + filename;Ofilepath = fpath;if (_access(fpath.data(), 0) != 0){cout << "找不到文件!" << endl;}else{finout.open(fpath, ios_base::in | ios_base::out);if (!finout.is_open()){cout << "文件打開失敗!" << endl;}else{openfilepath = filepath;cout << "文件打開成功!" << endl;}}}}/*退出文件系統*/ void quit1() {if (finout.is_open()){finout.close();}else{} }/*刪除目錄樹*/ void rd1(string str) {to_search = SPath + "/" + str;path = to_search;bool ifdo = true;if (strcmp(path.data(), newpath.data()) < 0){if (strcmp(newpath.data(), path.data()) != 0){cout << "該目錄正在使用,無法刪除!" << endl;ifdo = !ifdo;}else{}}else if (strcmp(newpath.data(), path.data()) == 0){cout << "該目錄正在使用,無法刪除!" << endl;ifdo = !ifdo;}if(ifdo){struct stat s;if (stat(path.data(), &s) == 0)//判斷路徑是否存在{if (s.st_mode&S_IFDIR)//路徑是目錄時{record[index] = to_search;//記錄當前文件目錄index++;DDRF();//第一次查找子文件LEindex = index;FEindex = 1;if (LEindex == 1)//沒有子文件夾{RemoveDirectory(record[0].data());}else{while (LEindex > FEindex)//有新增文件夾路徑,則繼續往下記錄新的文件夾和刪除文件{for (int j = FEindex; j < LEindex; j++){to_search = record[j];path = record[j];DDRF();}FEindex = LEindex;LEindex = index;}for (int j = LEindex - 1; j >= 0; j--)//從最新記錄的文件夾開始刪除,并置相應字符串為空{RemoveDirectory(record[j].data());record[j] = "";}}cout << "刪除目錄樹成功!" << endl;}else//路徑是文件時{cout << "請輸入一個目錄名!" << endl;}}else//路徑不存在{cout << "目錄不存在!" << endl;}/*重置記錄數為0,以供下一次使用*/index = 0;FEindex = 0;LEindex = 0;}to_search = "C:/FileSystem";path = "C:/FileSystem"; }/*讀文件*/ void read1() {char ch;if (finout.is_open()){ifstream fin;fin.open(Ofilepath.data(), ios::in);cout << "/" << endl<< "文件內容:" << endl;while (fin.get(ch)) cout << ch;cout << endl << "/" << endl;fin.close();}else{cout << "請先打開文件!" << endl;} }/*寫文件*/ void write1() {if (finout.is_open()){ofstream fout;fout.open(Ofilepath.data(), ios::out | ios::app);if (fout.is_open()){string write;cout << "以兩行空行作為輸入結束標志!" << endl;while (true){getline(cin, write);if (write != ""){fout << write << endl;}else{getline(cin, write);if (write == "")break;else continue;}}cout << "文件寫入結束!" << endl;fout.close();}else{cout << "錯誤!" << endl;}}else{cout << "請先打開文件!" << endl;} }總結
以上是生活随笔為你收集整理的文件管理系统_文件管理系统的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 用wxpython做ui_wxPytho
- 下一篇: windows href 可以设置hea