I'm currently building a project to practice file handling and I want to declare a vector of class like array of structure and check its size so that I could append the last vector size's object to the file. Is it possible?
#include <fstream>
#include <iterator>
#include <string>
#include <vector>
using namespace std;
class test {
public:
string name;
string nickName;
string phoneNumber;
string address;
};
vector <test> gymMember[10];
int main()
{
gymMember[0].name = "Lukas";
gymMember[0].nickName = "Naruto";
gymMember[0].phoneNumber = "0123";
gymMember[0].address = "22A";
gymMember[1].name = "Jack";
gymMember[1].nickName = "Eren";
gymMember[1].phoneNumber = "0589";
gymMember[1].address = "23A";
// I want to check the vector size so i could append the last vector index to a file (I know this will give an error but i wanna ask how to actually find the size)
int size = size(gymMember);
ofstream output_file("Contact.txt", ios::app);
// from here i want to append the last vector index to Contact.txt with the class name, nickName, phoneNumber, address
if (output_file.is_open()) {
output_file << gymMember[size].name << " " << gymMember[size].nickName << " " << gymMember[size].phoneNumber << " " << gymMember[size].adress << " " << endl;
}
output_file.close();
return 0;
}