Can somebody help me explain this function?

Hello! I need some help to understand this function.

Why a two dimension vector is needed here?
Thank you in advance!

void output_results(const vector<string> possibilities)
{
bool is_valid = false;
cout << "Possible result(s): \n";
for(int i = 0; i < possibilities.size(); i++)
{
for(int j = 0; j < possibilities[i].length(); j++)
{
if(!isalpha(possibilities[i][j]) && !isspace(possibilities[i][j]) && possibilities[i][j] != '.' && possibilities[i][j] != '?' && possibilities[i][j] != '!')
{
is_valid = false;
break;
}
else
is_valid = true;
}
if(is_valid)
cout << "Key " << i + 1 << ": " << possibilities[i] << endl;
}
}
It's not a 2D vector, but a vector of strings.

Both vectors and strings have a subscript operator. possibilities[i] gives you the string at index i in the vector. possibilities[i][j] gives you the character at index j in that string.
OK! Thank you for your help. I am trying making this function output the string at index 0, but the compiler gave me some error message:
Error 1 error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::basic_string<_Elem,_Traits,_Alloc>' (or there is no acceptable conversion)
2 IntelliSense: no operator "<<" matches these operands
operand types are: std::ostream << std::string


Below is my main function:

int main()
{
vector<string>msg;

msg.push_back("abcd");
msg.push_back("efgh");
msg.push_back("ijkl");
msg.push_back("mnop");

cout <<msg[0]<<endl;

system("pause");
return 0;
}

I would like to know the right way to do that. Thank you!
Have you included the <string> header?
No, I forgot to do that. That's the problem. Thank you for reminding me. It works now.
Topic archived. No new replies allowed.