-
problem
actually the problem is when storing the data.
when we try to retake the data , data is not found
struct rooms
{
int totrooms;
int *roomnums;
}rs;
constructor()
{
roomnums=new int(0);
void getdata()
{
cin>> totrooms;
rs.roomnums=new int(rs.totrooms);
for(int i=0;i<rs.totrooms;i++)
{
cin>>rs.roomnums[i];
file sr.write(.....);
}
this code will work but only once
-
constructor for a struct called rooms called constructor?
Are you trying to nest functions. This is not possible in c++. It can be approximated with functors but thats a different story.
Maybe you should totally describe what you are trying to accomplish.
-
There are a few problems with your code. But I think the main problem is that you are trying to use new to arrayafy (if thats a word) your pointer. This does not work. When you new something into your pointer it does not turn it into an array if something is already being pointed to by that pointer. Instead it moves the pointer to the new address of the newly allocated space and the old space is lost and you have a memory leak.
This line is your problem:
rs.roomnums=new int(rs.totrooms);
Instead you will have to use a linked list like CList.
CList <int, int> rs.roomnum;
rs.roomnum.AddTail(new int(rs.totrooms));
Something like that.