Click here to Skip to main content
16,015,635 members
Home / Discussions / ATL / WTL / STL
   

ATL / WTL / STL

 
GeneralGreat advice! Pin
mcase6-Jun-04 22:45
mcase6-Jun-04 22:45 
GeneralTo clarify Pin
mcase6-Jun-04 22:50
mcase6-Jun-04 22:50 
GeneralRe: To clarify Pin
Jason De Arte7-Jun-04 8:24
Jason De Arte7-Jun-04 8:24 
GeneralProblem using CResizableFormView with MSFLEXGRID control! Pin
Nguyễn Thiện Nhẫn4-Jun-04 18:33
Nguyễn Thiện Nhẫn4-Jun-04 18:33 
Generalquery reg STL maps Pin
Member 11501763-Jun-04 23:32
Member 11501763-Jun-04 23:32 
GeneralRe: query reg STL maps Pin
Paul Ranson4-Jun-04 3:02
Paul Ranson4-Jun-04 3:02 
GeneralRe: query reg STL maps Pin
Member 11501764-Jun-04 3:19
Member 11501764-Jun-04 3:19 
GeneralRe: query reg STL maps Pin
sas22224-Jun-04 4:47
sas22224-Jun-04 4:47 
i had a little time to delve into this, so here you go:

It appears that your map declaration is incomplete:

typedef map Map

should look like:

typedef map<int, one=""> Map

stl maps are templated classes, meaning at declartion time
the coder needs to tell the map what is being stored
in the map, in this case, an integer and a One object are
being stored in the map.

--

your One class should have the age
and salary members public (for the quicky example);
I changed your One class to look like

class One
{
public:
One() {age = -1; sal = -1;}; //ctor
int age; // these could be private wwith public accessors..
int sal;

protected:

private:
};

--
also in your while loop, you should
instantiate a new One object (either
on the heap with 'new' or on the stack like below):

when assigning the int and the One object to the
map, stl will use the One object's copy constructor
to make a copy of the object to store in the map;


while(!file.eof())
{
One newOne; // create new Oneobject on the stack
newOne.age = 50;
newOne.sal = 1000;
theMap.insert(Map::value_type(index, newOne));
index++;
}


--------

when printing out your map, your code as written assumes the One
class has an overloaded operator <<; you can also print the indiviudals members like so (note the accessing of the One object's members):

cout << endl << "The class "<< (*theIterator).first;
cout << endl << "The class "<< ((*theIterator).second).age << " | " << ((*theIterator).second).sal << endl ;


--

here's a cut and paste of my changes to your example:
i compile it but did not execute it, btw...

class One
{
public:
One() {age = -1; sal = -1;}; //ctor init of members
int age;
int sal;

protected:

private:
};




typedef map<int, one=""> Map;
int main()
{
Map theMap;
Map::iterator theIterator;

//Open the file
//Read each line of file and store in class variables
int index = 0;
while(!file.eof())
{
One newOne;
newOne.age =50;
newOne.sal = 1000;
theMap.insert(Map::value_type(index, newOne));
index++;

}
//to get the class
theIterator = theMap.find(0);
//Get the entire first record ?How should I achieve this which is stored in a class?

cout << endl << "The class "<< (*theIterator).first;
cout << endl << "The class "<< ((*theIterator).second).age << " | " << ((*theIterator).second).sal << endl ;
return 0;
}






sas
GeneralRe: query reg STL maps Pin
sas22224-Jun-04 5:26
sas22224-Jun-04 5:26 
GeneralRe: query reg STL maps Pin
sas22224-Jun-04 5:32
sas22224-Jun-04 5:32 
GeneralRe: query reg STL maps Pin
Paul Ranson4-Jun-04 5:38
Paul Ranson4-Jun-04 5:38 
QuestionAnybody tell me how to use IStream correctly? Pin
max_xiayi3-Jun-04 18:59
max_xiayi3-Jun-04 18:59 
AnswerRe: Anybody tell me how to use IStream correctly? Pin
Todd Smith4-Jun-04 13:22
Todd Smith4-Jun-04 13:22 
AnswerRe: Anybody tell me how to use IStream correctly? Pin
f649-Jun-04 6:31
f649-Jun-04 6:31 
GeneralBase Class Undefined Pin
TFrancis3-Jun-04 7:56
TFrancis3-Jun-04 7:56 
QuestionHow to call methods of an appobject directly? Pin
Roozbeh692-Jun-04 4:01
professionalRoozbeh692-Jun-04 4:01 
QuestionWhat a sh##t!!! Pin
El'Cachubrey2-Jun-04 2:25
El'Cachubrey2-Jun-04 2:25 
AnswerRe: What a sh##t!!! Pin
sas22222-Jun-04 3:55
sas22222-Jun-04 3:55 
Generalshell programming Pin
sas22221-Jun-04 8:56
sas22221-Jun-04 8:56 
GeneralRe: shell programming Pin
Prakash Nadar2-Jun-04 7:10
Prakash Nadar2-Jun-04 7:10 
GeneralRe: shell programming Pin
sas22222-Jun-04 7:33
sas22222-Jun-04 7:33 
GeneralRe: shell programming Pin
Prakash Nadar2-Jun-04 15:49
Prakash Nadar2-Jun-04 15:49 
GeneralRe: shell programming Pin
sas22223-Jun-04 6:07
sas22223-Jun-04 6:07 
GeneralDebugging ATL control Pin
roel_1-Jun-04 5:01
roel_1-Jun-04 5:01 
GeneralRe: Debugging ATL control Pin
roel_1-Jun-04 5:15
roel_1-Jun-04 5:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.