Last active
May 11, 2018 16:40
-
-
Save MORTAL2000/b95707890c90e1463731b63f386e43c4 to your computer and use it in GitHub Desktop.
This file contains 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 characters
#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'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment