Ask Your Question

bella cutey's profile - activity

2013-04-03 07:03:31 -0600 answered a question Write to a file from a C++ ROS node?

void insert_node(char* name,int roll_no ,char* sems,char* major,float gpa) { fstream myfile; myfile.open("myfile.txt", ios::out|ios::binary|ios::app); Node* newptr = new Node(/name,roll_no,sems,major,gpa/); if(firstptr==NULL && lastptr==NULL) { firstptr = newptr; lastptr = newptr; } else if((newptr->getname()>firstptr->getname())&&(newptr->getname()>lastptr->getname())) { lastptr->nextptr = newptr; newptr->nextptr = NULL; lastptr = newptr; } else if(newptr->getname()<firstptr->getname()) { newptr->nextptr = firstptr; firstptr = newptr; } else { Node* tempptr; tempptr = firstptr; while(newptr->getname()> tempptr->nextptr->getname()) { tempptr = tempptr->nextptr; } newptr->nextptr = tempptr->nextptr; tempptr->nextptr = newptr; }

                   myfile.write((Node*)&newptr, sizeof(newptr)); //i have error on thiis line but if i put char* instead of Node* then i got a different type of output in my file plzz anyone help me.. :(

                   myfile.close();
                  }