Efficiency?

Apr 3, 2011 at 4:54pm
So, I created a "conversation" program in which the user inputs something like, "hi" and the program responds. The way I analyzed the in put was:

1
2
3
4
5
6
string input;

if(input.find("Hi")!=string::npos)
{
	cout<<"Hey there! What's up?";
}


The person teaching me C++ (I'm not taking classes) said that this was a very inefficient way to do this. He said that !=string::npos was not a good way to do it.

Does anyone know a quicker, better way to do this?
Apr 3, 2011 at 5:08pm
No, this is the correct way to do this.
Although you should ask him why he thinks it is bad and what he suggests instead.
Apr 4, 2011 at 1:32am
Ok, thanks!
Topic archived. No new replies allowed.