I am looping through std::vector and std::string array to find matches from the vector.
Example:
#include <iostream>
#include <vector>
#include <string>
int main()
{
std::cout << "Searching...\n";
std::vector<std::string> myVector;
myVector.push_back("Word");
myVector.push_back("Word2");
myVector.push_back("Word4");
myVector.push_back("Word6");
myVector.push_back("Word7");
std::string myStringArr[] =
{
"Word",
"Word1",
"Word2",
"Word3",
"Word4",
"Word5",
"Word6",
"Word7"
};
for (auto Vec : myVector)
{
for(auto Str : myStringArr)
{
if(Vec == Str)
{
std::cout << "Found: " << Vec << std::endl;
}
}
}
std::cin.ignore(2);
return 0;
}
This works fine. But I am coming from C language(trying to get into C++ 11), and not sure if this is the best solution.
Platform is windows, and I do not (currently) use any external libraries like boost, as you can see from the code.
Is there a better / cleaner way to achieve the same result?