fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4.  
  5. class MyClass {
  6. public:
  7. MyClass(std::string s, int i) {
  8. StringValue = s;
  9. IntValue = i;
  10. }
  11.  
  12. std::string StringValue;
  13. int IntValue;
  14. };
  15.  
  16. int main() {
  17. std::vector<MyClass> MyVector;
  18. for (int i = 1; i <= 2; i++) {
  19. MyClass c("", i);
  20. MyVector.push_back(c);
  21. }
  22.  
  23. std::cout << MyVector[0].IntValue << ", " << MyVector[1].IntValue;
  24. }
Success #stdin #stdout 0s 3432KB
stdin
Standard input is empty
stdout
1, 2