string with array

closed account (G60iz8AR)
Does anyone know how to print strings from array with a letter starting with n?

// Filter: only print those strings from the array that start with letter 'n'

bool startsWith_n( string word )
{
return false; // just to make it compile. you change as needed
}
You already asked that question here:
http://www.cplusplus.com/forum/beginner/113350/
and here:
http://www.cplusplus.com/forum/beginner/114024/

You need to solve it yourself. We're not going to do your homework for you.

Hint #1. Do you know how to get the first character of a string?
If not, go look up the string class.
http://www.cplusplus.com/reference/string/string/

Do you know how to compare two characters?
If not, go study if statements
http://www.cplusplus.com/doc/tutorial/control/


Last edited on
Here you go, but I suggest you try and learn to solve problems on your own if you want to make it anywhere in life:

1
2
3
4
5
6
7
for(int i = 0; i < arrayLength; i++)
{
	if(myArray[i].front == 'n')
	{
		//Do stuff
	}
}
Topic archived. No new replies allowed.