Last active
May 11, 2018 16:40
-
-
Save MORTAL2000/b95707890c90e1463731b63f386e43c4 to your computer and use it in GitHub Desktop.
Revisions
-
MORTAL2000 revised this gist
May 11, 2018 . 1 changed file with 0 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -42,9 +42,7 @@ int main() while (std::getline(fin, temp)) { if (i++ % 2 == 0) menuOrders.emplace_back(menuItems{}); if (std::stringstream(temp) >> price) menuOrders.back().price = price; -
MORTAL2000 renamed this gist
May 11, 2018 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
MORTAL2000 created this gist
May 11, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,62 @@ #include <iostream> #include <iomanip> #include <string> #include <fstream> #include <vector> #include <sstream> /* test.txt Plain Egg 1.45 Bacon and Egg 2.45 Muffin 0.99 French Toast 1.99 Fruit Basket 2.49 Cereal 0.69 Coffee 0.50 Tea 0.75 */ struct menuItems { std::string item; double price; }; int main() { std::vector<menuItems> menuOrders; std::ifstream fin("test.txt"); std::string temp; double price; int i = 0; while (std::getline(fin, temp)) { if (i++ % 2 == 0) { menuOrders.emplace_back(menuItems{}); } if (std::stringstream(temp) >> price) menuOrders.back().price = price; else menuOrders.back().item = temp; } fin.close(); for (const auto& order : menuOrders) { std::cout << std::setw(20) << std::left << order.item; std::cout << std::setw(10) << std::right << order.price << '\n'; } }