ShopSysCostomer::ShopSysCostomer() :is_member(false), p_identity(NULL) { /* Firstly the system should import goods info */ fstream fgoods_list, fgoods; u_int read_line_num = 0; string goods_file_name, goods_info; fgoods_list.open("goods_list.txt",ios::in); if (!fgoods_list) { cerr << "Exception : Cannot Find File goods_list.txt. " << endl; fgoods_list.close(); system("pause"); exit(1); } while (!fgoods_list.eof()) { read_line_num++; getline(fgoods_list, goods_file_name); /* Read Each Goods File */ if (goods_file_name == "") break; fgoods.open((".\\goods\\"+goods_file_name),ios::in); if (!fgoods_list) { cerr << "Exception : Cannot Find File \"" << goods_file_name << "\" in folder goods\\. " << endl; fgoods.close(); system("pause"); exit(1); } getline(fgoods, goods_info); if ( regex_match(goods_info, Id_Goods_File_Pattern) ) { vector<string> info = str_Split_file(goods_info); id_goods_map[(info[0])] = Goods(info[1],info[2],info[0],info[3]); } else { cerr << "Exception : Product information file format does not conform regex. " << endl; fgoods.close(); system("pause"); exit(1); } fgoods.close(); } fgoods_list.close(); }
void CityTurnLogger::logTurn(uint8_t turn, const City &city) { std::cout << std::setfill('0'); std::cout << "T" << std::setw(2) << static_cast<int>(turn) << ": " << city << " " << goods_ << " "; for (int i = 0; i < city.buildingQueue_.size(); ++i) { if (i == 0 || city.buildingQueue_[i]->accumulatedHammers() > 0) { std::cout << *city.buildingQueue_[i] << (city.buildingQueue_[i]->isComleted() ? "* " : " "); } } for (int i = 0; i < events_.size(); ++i) { std::cout << events_[i] << " "; } events_.clear(); if (!goodsChange_.isZero()) { std::cout << std::setfill(' '); std::cout << "±FPС: " << goodsChange_.food << "/" << goodsChange_.hammers << "/" << goodsChange_.commerce; goodsChange_ = Goods(); } std::cout << std::endl; }
/** * read the file. */ Goods::Goods(std::ifstream& is):count(1), discount(1){ std::string strin, str; while(is >> strin){ str += " " + strin; } /** * [inString store all the input data.] * @str [store the input data temporarily] */ std::istringstream inString(str); int commodity; std::string name; std::string origin; int benchmark; while(inString){ inString >> commodity >> name >> origin >> benchmark; allGoods.push_back(Goods(commodity, name, origin, benchmark)); } allGoods.pop_back(); }