Reputation: 424
How can I use substr()
on objects in vector of strings?
vector<string>text[7];
for (int j=0;j<7;j++)
{
for (int y=0;y <text[i].size(); y++)
{
text[j][y].substr(1,1);
}
}
Upvotes: 0
Views: 1359
Reputation: 50657
Change
for (int y=0;y <text[i].size(); i++)
to
for (int y=0; y<text[j].size(); j++) // as no "i" here
substr()
will return a string
, so you probably need to use a string
to receive its return value (although can still compile successfully if not), otherwise, it's meaningless to do substr()
here.
string str = text[j][y].substr(1,1);
Upvotes: 2
Reputation: 3806
for (int y=0;y <text[i].size(); i++)
Try increasing y
instead of i
for (int y=0;y <text[i].size(); y++)
Normally, people uses i,j,k,l
for nested loops. But if you like y, you should increase it.
Upvotes: 1