Created
          September 18, 2014 18:30 
        
      - 
      
 - 
        
Save matutter/2d3ad2d17ae62fce1f61 to your computer and use it in GitHub Desktop.  
    Multiplicity&collections .cpp example
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #include <string> // for string :: iterator | |
| #include <fstream> // for file stuff | |
| #include <cstdlib> // for atoi | |
| #include <vector> // for vectors | |
| #include <cstring> // for c_str | |
| #include <iostream> // for cout/in | |
| using namespace std; | |
| class myclass | |
| { | |
| public: | |
| int from; | |
| char on; | |
| int to; | |
| myclass(){} | |
| myclass(string from, string on, string to) | |
| { | |
| this->from = atoi( from.c_str() ); | |
| this->on = on[0]; | |
| this->to = atoi( to.c_str() ); | |
| } | |
| friend ostream& operator<< (ostream &out, myclass &s); | |
| }; | |
| int main(int argc, char const *argv[]) | |
| { | |
| myclass m("2", "a", "2"); | |
| vector<myclass> states; | |
| states.push_back( m ); | |
| cout << m << endl; | |
| return 0; | |
| } | |
| ostream& operator<< (ostream &out, myclass &s) | |
| { | |
| out << s.from << " " << s.on << " " << s.to << endl; | |
| return out; | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment