Lets say that we have a specific string:
string a[]={"ab","cd","ef"}
and we want a specific string when we input first character of the string:
for example:
input: c
output: "cd"
what i was thinking is that:
so let’s say we assign char x for the input value.
and then using the loop to go through the list, but i’m stuck of how char x is going to stop the loop and printing the specific string.
other question is how its going to be different to find a letter thats inside the string. for example inputing: d and output: “cd”
I will answer both of your questions (even though you should keep it to one question per “question”).
To stop a loop you use the
breakstatement.To find a character (or a string) in a string you use the
std::string::findfunction.Now combining them:
Note: The above code contains two features from the “new” C++11 standard: Range-based for-loops; And lambda functions.