/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <iostream>
#include <string>
#include <vector>
usingnamespace std;
int main()
{
vector<string>x;
vector<string>d;
x.push_back("dog");
x.push_back("catd");
for(int i =0;i<x.size();i++){
for(int j=0;j<x.size();j++){
if(x[i][j]=='d'){
d.push_back(x[i]);
}
}
}
for(int v=0;v<d.size();v++){
cout<<d[v];
}
return 0;
}
I prefer using range-based for loops when dealing with C++ containers if I need to access every element. No mistakes from going out of bounds.
http://en.cppreference.com/w/cpp/language/range-for