fork download
  1. #include <vector>
  2. #include <iostream>
  3. #include <string>
  4.  
  5. struct Employee {
  6. std::string id;
  7. std::string name;
  8. std::string f_name;
  9. std::string password;
  10. };
  11.  
  12. int main() {
  13.  
  14. std::vector<Employee> employees; // vector for keeping elements together
  15.  
  16. for (int i = 0; i<5; i++) {
  17. // push_back adds new element in the end
  18. employees.push_back(Employee{ "12345", "Naser", "Sadeghi", "12345" });
  19. }
  20. std::cout << employees.size() << std::endl; // 5 returns how many elements do you have.
  21. std::cout << employees[0].name; // you access name field of first element (counting starts from 0)
  22.  
  23. return 0;
  24. }
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
5
Naser