I am calling a function in a loop which takes argument as structure pointer (st *ptr) and i need to push_back this data to a STL vector and display the content in a loop.How can i do it? please help.
struct st
{
int a;
char c;
};
typedef struct st st;
function(st *ptr)
{
vector<st*>myvector;
vector<st*>:: iterator it;
myvector.push_back(ptr);
it=myvector.begin();
cout<<(*it)->a<<(*it)->c<<endl;
}
is this correct? i am not getting the actual output.
Code snippet-----
void Temperature_sensor::temp_notification()//calling thread in a class------
{
cout<<"Creating thread to read the temperature"<<endl;
pthread_create(&p1,NULL,notifyObserver_1,(void*)(this));
pthread_create(&p2,NULL,notifyObserver_2,(void*)(this));
pthread_join(p1,NULL);
pthread_join(p2,NULL);
}
void* Temperature_sensor::notifyObserver_1(void *data)
{
Temperature_sensor *temp_obj=static_cast<Temperature_sensor *>(data);
(temp_obj)->it=(temp_obj)->observers.begin();
ifstream inputfile("temp.txt");//Reading a text file
while(getline(inputfile,(temp_obj)->line))
{
stringstream linestream((temp_obj)->line);
getline(linestream,(temp_obj)->temperature,':');
getline(linestream,(temp_obj)->temp_type,':');
cout<<(temp_obj)->temperature<<"---"<<(temp_obj)->temp_type<<endl;
stringstream ss((temp_obj)->temperature);
stringstream sb((temp_obj)->temp_type);
sb>>(temp_obj)->c_type;
ss>>(temp_obj)->f_temp;
cout<<"____"<<(temp_obj)->f_temp<<endl;
(temp_obj)->a.temp=(temp_obj)->f_temp;
(temp_obj)->a.type=(temp_obj)->c_type;
cout<<"------------------q"<<(temp_obj)->a.type<<endl;
(*(temp_obj)->it)->update(&(temp_obj)->a);//Calling the function -------
}
input file temp.txt 20:F 30:C 40:c etc
void Temperature_monitor::update(st *p) {}//need to store in a vector------