summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--platypus/platypus.cpp12
1 files changed, 3 insertions, 9 deletions
diff --git a/platypus/platypus.cpp b/platypus/platypus.cpp
index 094fae5..fef02e6 100644
--- a/platypus/platypus.cpp
+++ b/platypus/platypus.cpp
@@ -92,17 +92,11 @@ Platypus Platypus::hatch() const {
if (this->alive) {
int newGender = rand() & 1;
std::string newName;
- std::ifstream namesFile;
+ // If the platypus is male, pick a random male name; otherwise, pick a
+ // female name.
+ std::ifstream namesFile(newGender ? "mnames.txt" : "fnames.txt");
std::vector<std::string> names;
- // If the platypus is male, pick a random male name; ...
- if (newGender) {
- namesFile.open("mnames.txt");
- } else {
- // ... otherwise, pick a female name
- namesFile.open("fnames.txt");
- }
-
while (std::getline(namesFile, newName)) {
names.emplace_back(newName);
}