it's the cin.get()'s you have there... here's what your code should look like:
Code:
#include <iostream>
//#include <fstream> //used for File I/O - you don't need it here
#include <string>
using namespace std;
int main()
{
string talk;
int search;
for(;;) //this is the best way to write an infinite loop
{
getline(cin, talk, '\n');
search = talk.find("hi",0);
if (search >= 0)
{
cout<<"hello\n"; //put a newline to seperate
//input from output
}
//cin.get(); //what were these for?
//cin.get();
}
return 0; //you should return 0 at the end of main
}
here's another way it could be done (note the use of strstr in the conditional)
Code:
#include <iostream>
#include <string>
int main()
{
std::string talk;
for(;;) //this is the best way to write an infinite loop
{
getline(std::cin, talk, '\n');
if (strstr(talk.c_str(),"hi")) //enter this block if "hi" is found in talk
{
std::cout<<"hello\n"; //put a newline to seperate input from output
}
}
return 0; //you should return 0 at the end of main
}