Advertisement
Guest User

Untitled

a guest
Nov 2nd, 2010
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 0 0
  1. #include <iostream>
  2. #include <list>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. struct testStr
  8. {
  9.     string str;
  10.     int a;
  11. };
  12.  
  13. class testCls
  14. {
  15. public:
  16.     testCls ()
  17.     {
  18.         cout << "Constructor" << endl;
  19.     }
  20.     ~testCls ()
  21.     {
  22.         cout << "Destructor" << endl;
  23.     }
  24.     void fillList()
  25.     {
  26.         testStr tmp;
  27.         for (int i =0; i<10; i++)
  28.         {
  29.             char t[2];
  30.             t[0] = i + 61;
  31.             t[1] = '\0';
  32.             tmp.str = t;
  33.             tmp.a = i;
  34.             lst.push_back (tmp);
  35.         }
  36.     }
  37.     void printList()
  38.     {
  39.         list<testStr>::iterator it;
  40.         for (it = lst.begin(); it != lst.end(); it++)
  41.         {
  42.             cout << it->str << ", "<< it->a << endl;       
  43.         }  
  44.     }
  45. private:
  46.     list <testStr> lst;
  47. };
  48.  
  49. int main()
  50. {
  51.     testCls cls;
  52.     cls.fillList();
  53.     cls.printList();
  54.     return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement