#include #include #include #include #include "Constant.h" using namespace std; map loadSetup(string setupFileName) { // 定义文件流,用于打开文件 fstream fs; fs.open(setupFileName, ios::in); // 定义变量,用于存放行 string line; // 定义map map mapSetup; // 逐行读取 if (!fs) { cout << "Cannot open file.\n"; return mapSetup; } else { // 逐行读取 while (getline(fs, line)) { // 移除空格 line.erase(std::remove(line.begin(), line.end(), ' '), line.end()); // 是否以#开头 if (line[0] == '#') { continue; } // 定义分隔符 char delimiter = '='; // 取分隔符的位置 size_t pos = line.find(delimiter); // 如果分隔符找不到 if (pos == string::npos) { cout << "Not found!" << endl; return mapSetup; } // 取key string key = line.substr(0, pos); // 取value string value = line.substr(pos + 1); mapSetup.insert(std::pair(key, value)); } } return mapSetup; };