Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct Person {
- std::string name;
- int initialMoney;
- int currentMoney;
- Person(const std::string &name, int money = 0, int currentMoney = 0)
- {
- this->name = name;
- this->initialMoney = money;
- this->currentMoney = currentMoney;
- }
- };
- int main()
- {
- std::vector<Person> persons;
- int index = 0;
- int maxIndex = 0;
- std::ofstream fout("gift1.out");
- std::ifstream fin("gift1.in");
- // Obtain max number of names!
- fin >> maxIndex;
- // Create a person for every name...
- for (index = 0; maxIndex != index; index++) {
- std::string tmpName;
- fin >> tmpName;
- std::cout << "Inserting " << index << ": " << tmpName << std::endl;
- persons.push_back(Person(tmpName, 0, 0));
- }
- std::cout << "Checking if the proper person's name is there: \n";
- // Check to see if the person's name is being read correctly
- for (index = 0; maxIndex != index; index++) {
- std::cout << "Reading " << index << ":" << persons[index].name << std::endl;
- }
- std::cout << "Changing a single element of an array: \n";
- persons[1].name = (char *)"John";
- for (index = 0; maxIndex != index; index++) {
- std::cout << "Reading " << index << ":" << persons[index].name << std::endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment