Ted
Ted

Reputation: 15

Can you Iterate through member variables using a for loop, if a vector is of a class

for (std::string& request : recData.getReqest()) //recData is a vector 
    {
    }

recData is a vector which stores objects of an X type, X class has a member variable which is "std::string request;" and as I iterate through the for loop I want all objects within recData to have their request member variable processed. Is this possible?

Upvotes: 1

Views: 66

Answers (1)

Sam Varshavchik
Sam Varshavchik

Reputation: 118330

It's certainly possible, by changing the for loop and using one extra statement:

for (auto &r: recData)
{
    std::string &request = r.request;

    // Here's your request, for your loop.
}

Upvotes: 1

Related Questions