| | |
Problem in using Map
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Aug 2007
Posts: 49
Reputation:
Solved Threads: 0
Hi
My problem statement is as follows :-
I have set of processes all having unique name say PROG,PROG1,PROG2 etc.
Now with each of these processes different integer values are being associated say min_time, max_time,median_time.
What i want is to create a map of all these processes and associate the respective property with each of them. So for that what i did is
/...
struct Properties
{
int MinTime;
int MaxTime;
int MedianTime;
};
typedef std::map < std::string,int,Properties > ProcessMap;
ProcessMap pmap;
.../
Now how to write a code to insert the name of the process if it is not present in the list and then add all the values to it.(Provided that all values are being taken as an input from user already). Also i need to increment or decrement the existing values of MinTime, MaxTime and MedianTime for a particular process so how to do that also..
Kindly help..
My problem statement is as follows :-
I have set of processes all having unique name say PROG,PROG1,PROG2 etc.
Now with each of these processes different integer values are being associated say min_time, max_time,median_time.
What i want is to create a map of all these processes and associate the respective property with each of them. So for that what i did is
/...
struct Properties
{
int MinTime;
int MaxTime;
int MedianTime;
};
typedef std::map < std::string,int,Properties > ProcessMap;
ProcessMap pmap;
.../
Now how to write a code to insert the name of the process if it is not present in the list and then add all the values to it.(Provided that all values are being taken as an input from user already). Also i need to increment or decrement the existing values of MinTime, MaxTime and MedianTime for a particular process so how to do that also..
Kindly help..
•
•
Join Date: Dec 2006
Posts: 1,089
Reputation:
Solved Threads: 164
c++ Syntax (Toggle Plain Text)
struct Properties { int mint; int maxt; int medt; Properties( int a, b, c ) : mint(a), maxt(b), medt(c) {} }; typedef std::map < std::string, Properties > ProcessMap; bool is_there( const ProcessMap& pmap, const std::string& pname ) { return pmap.find(pname) != pmap.end() ; } void insert( ProcessMap& pmap, const std::string& pname, int mint, int maxt, int medt ) { pmap[pname] = Properties(mint,maxt,medt) ; } void incr_times( ProcessMap& pmap, const std::string& pname ) { Properties& p = pmap[pname] ; ++p.mint ; // etc }
Last edited by vijayan121; Nov 20th, 2007 at 10:06 am.
•
•
Join Date: Aug 2007
Posts: 49
Reputation:
Solved Threads: 0
While using the code provided by you i'm facing one compilation problem
My code is as follows
struct Properties
{
int Min;
int Max;
Properties( int a,int b): Min(a),Max(b)
{ }
};
typedef std::map < std::string, Properties > ProcessMap;
ProcessMap pmap;
void insert( ProcessMap& pmap, const std::string& pname,int mint, int maxt)
{
pmap[pname] = Properties(mint,maxt) ;
}
On the line in Bold i m getting compilation error as "no matching function for call to `NewProperties::NewProperties()'" What can be the reason for this..
My code is as follows
struct Properties
{
int Min;
int Max;
Properties( int a,int b): Min(a),Max(b)
{ }
};
typedef std::map < std::string, Properties > ProcessMap;
ProcessMap pmap;
void insert( ProcessMap& pmap, const std::string& pname,int mint, int maxt)
{
pmap[pname] = Properties(mint,maxt) ;
}
On the line in Bold i m getting compilation error as "no matching function for call to `NewProperties::NewProperties()'" What can be the reason for this..
•
•
Join Date: Dec 2006
Posts: 1,089
Reputation:
Solved Threads: 164
i'm sorry; it was a mistake made by me. to use the [] operator on a map, a default constructor is needed for the data.
another way is to use the insert method of the map (instead of the operator[]).
struct Properties
{
int Min;
int Max;
Properties( int a = 0, int b = 0 ): Min(a),Max(b){}
}; Last edited by vijayan121; Nov 21st, 2007 at 9:50 am.
![]() |
Similar Threads
- Composed STL types (C++)
- Problems with mapping network drive (Networking Hardware Configuration)
- GoDaddy domain IP address mapping (Domains and DNS)
- Problem with VC++ (C++)
- Plz help......Map-coloring problem (C++)
- Help (Database Design)
- Using map<> with classes (C++)
- problem in java cobe (Java)
- Problem with pointers (C++)
- Problem with foreach when using linking (PHP)
Other Threads in the C++ Forum
- Previous Thread: check if a dll file is currently in use
- Next Thread: Network programing using ACE framework and C++
Views: 1669 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer display dll email encryption error file format forms fstream function functions game generator getline givemetehcodez graph iamthwee ifstream image input int java lib loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg search sort sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






