fork(1) download
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4.  
  5. typedef std::string String;
  6. typedef std::vector<String> StringVector;
  7.  
  8. class StringVectorWrapper {
  9. StringVector vector;
  10. public:
  11. operator StringVector&() {
  12. return vector;
  13. }
  14.  
  15. StringVectorWrapper& operator << (const String& str) {
  16. vector.push_back(str);
  17. return *this;
  18. }
  19. };
  20.  
  21. void printVector(const StringVector& vector) {
  22. for(StringVector::const_iterator it = vector.begin(); it != vector.end(); it++)
  23. std::cout << *it << std::endl;
  24. }
  25.  
  26. int main(void) {
  27.  
  28. StringVectorWrapper w;
  29. w << "A" << "B";
  30. printVector(w);
  31.  
  32. printVector(StringVectorWrapper() << "Z" << "W");
  33.  
  34.  
  35. return 0;
  36. }
Success #stdin #stdout 0s 2988KB
stdin
Standard input is empty
stdout
A
B
Z
W