Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string>
- #include <fstream>
- #include <vector>
- struct Warehouse {
- std::string name;
- double price;
- int quantity;
- };
- void printInfo(std::vector<Warehouse> arr) {
- for (size_t i = 0; i < arr.size(); i++)
- {
- std::cout << "Name: " << arr[i].name << std::endl;
- std::cout << "Price: " << arr[i].price << std::endl;
- std::cout << "Quantity: " << arr[i].quantity << std::endl << std::endl;
- }
- }
- void readFile(const std::string fileName, std::vector<Warehouse> &products, std::vector<Warehouse> &deficiency) {
- std::ifstream FILE;
- FILE.open(fileName);
- if (!FILE) {
- std::cout << "Unable to open file";
- exit(1);
- }
- std::string sName;
- double sPrice;
- int sQuantity;
- while (FILE >> sName >> sPrice >> sQuantity) {
- Warehouse temp;
- temp.name = sName;
- temp.price = sPrice;
- temp.quantity = sQuantity;
- if (temp.quantity == 0) {
- deficiency.push_back(temp);
- }
- products.push_back(temp);
- }
- FILE.close();
- }
- void writeFile(const std::string fileName, std::vector<Warehouse> deficiency) {
- std::ofstream outData;
- outData.open(fileName);
- if (!outData) {
- std::cout << "Unable to open file";
- exit(1);
- }
- while (deficiency.size() != 0) {
- Warehouse temp = deficiency.back();
- outData << temp.name << std::endl;
- outData << temp.price << std::endl;
- outData << temp.quantity << std::endl;
- deficiency.pop_back();
- }
- outData.close();
- }
- int main(int argc, char* argv[]) {
- std::vector<Warehouse> products;
- std::vector<Warehouse> deficiency;
- readFile(argv[1], products, deficiency);
- printInfo(products);
- writeFile("out.txt", deficiency);
- std::cin.get();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement