Skip to content

Instantly share code, notes, and snippets.

@matutter
Created September 18, 2014 18:30
Show Gist options
  • Save matutter/2d3ad2d17ae62fce1f61 to your computer and use it in GitHub Desktop.
Save matutter/2d3ad2d17ae62fce1f61 to your computer and use it in GitHub Desktop.
Multiplicity&collections .cpp example
#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