Re: [C++] Help!: map<userdefined*, vector<int>>
From: Mark (mark_netNews_at_hotmail.com)
Date: 06/22/04
- Next message: Ioannis Vranos: "Re: New Online C++ magazine launched!"
- Previous message: Mark : "Re: do thing with the inputs"
- Next in thread: Chris Val: "Re: [C++] Help!: map<userdefined*, vector<int>>"
- Maybe reply: Chris Val: "Re: [C++] Help!: map<userdefined*, vector<int>>"
- Maybe reply: Jerry Coffin: "Re: [C++] Help!: map<userdefined*, vector<int>>"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 21 Jun 2004 21:44:20 -0400
On 21 Jun 2004 17:05:45 -0700, email_entropy123@yahoo.com (entropy123)
wrote:
>Hi All,
>
>I'm attempting to make a map of vectors, where the key is a user
>defined class.
>
>typedef std::map< Data*, std::vector <int> > vmap;
>
>Is what I'm working with right now. I can't figure out how to add/take
>out items to this structure.... I'm not sure I can use Data* as a key
>for starters...
>
>Though, in a pinch, I would take advice on a:
>
>typedef std::map< int, std::vector <int> > vmap;
>
>implementation...
>
>Any suggestions?
>Thanks,
>ent
Perhaps this might help
#include <iostream>
#include <string>
#include <vector>
#include <map>
using std::cout;
using std::endl;
using std::map;
using std::string;
using std::vector;
using std::ostream;
//using namespace std; is not as 'tedious'
class Foo
{
private:
string Data;
public:
Foo() : Data( "Foo" ) {}
Foo( const string& S ) : Data( S ) {}
string Print() const { return Data; }
friend ostream& operator << ( ostream& Out, const vector<Foo>& B
)
{
vector<Foo>::const_iterator Pos = B.begin();
for( Pos; Pos != B.end(); ++Pos )
Out << Pos->Print() << endl;
return Out;
}
};
int main()
{
std::map<std::string, std::vector<Foo> > MyMap;
Foo A, B( "Hello" ), C( "World" );
vector<Foo> V; // Fill the vector
V.push_back( A );
V.push_back( B );
V.push_back( C );
MyMap[ "A" ] = V; // Now we're ready. Create string, vector pair
std::map<std::string, std::vector<Foo> >::iterator Pos =
MyMap.begin();
cout << "Key (" << Pos->first << ") " << endl << Pos->second;
return 0;
}
Mark
------------------------------------------------------------------------
If I wanted to measure the natural resonances of any object
-- bell, Helmholz resonator -- I imagine that I would get a better
result by rigging up some kind of continuous exciter than by
attempting to analyze an impulse response
- Next message: Ioannis Vranos: "Re: New Online C++ magazine launched!"
- Previous message: Mark : "Re: do thing with the inputs"
- Next in thread: Chris Val: "Re: [C++] Help!: map<userdefined*, vector<int>>"
- Maybe reply: Chris Val: "Re: [C++] Help!: map<userdefined*, vector<int>>"
- Maybe reply: Jerry Coffin: "Re: [C++] Help!: map<userdefined*, vector<int>>"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|