Ranjitha
Ranjitha

Reputation: 81

Structure of vectors C++

is there a way to clear a structure of vectors at a time using a single statement ? i.e. struct AStruct { vector StringList; vector DistanceList; }A;

i want both the vectors using a single statement.

Upvotes: 0

Views: 1812

Answers (1)

user2100815
user2100815

Reputation:

Sure:

AStruct a;
// stuff
a = AStruct();  // clear it

However, I would probably give myself a function:

struct AStruct { 
   vector <string> StringList; 
   vector <string> DistanceList; }
   void clear() {
       StringList.clear();
       DistanceList.clear();
   }
};

You can then say:

AStruct a;
// stuff
a.clear();  // clear it

which is perhaps easier to understand.

Upvotes: 2

Related Questions