NX二次開發-讀檔案
阿新 • • 發佈:2020-12-14
NX二次開發-讀檔案
1 bool Common::ReadFile(const std::string& fileName, std::vector<std::string>& txtLines) 2 { 3 if (!CheckFileExist(fileName)) 4 { 5 return false; 6 } 7 8 std::ifstream ifs(fileName.c_str(), std::ios_base::in); 9 if(!ifs.is_open()) 10 { 11 return false; 12 } 13 14 std::string currentLine; 15 while (std::getline(ifs, currentLine)) 16 { 17 txtLines.push_back(currentLine); 18 } 19 ifs.close(); 20 return true; 21 }
1 boolCommon::CheckFileExist(const std::string& fileName) 2 { 3 if (fileName.empty()) 4 { 5 return false; 6 } 7 8 std::ifstream ifs(fileName.c_str(), std::ios_base::in); 9 10 if (ifs.is_open()) 11 { 12 ifs.close(); 13return true; 14 } 15 else 16 { 17 return false; 18 } 19 }