Use getline(). I remember you arguing how getline() is better than cin :rolleyes:Quote:
Originally posted by RoD
i'm stuck guys. if i enter more than one keyword she responds and dumps.
Printable View
Use getline(). I remember you arguing how getline() is better than cin :rolleyes:Quote:
Originally posted by RoD
i'm stuck guys. if i enter more than one keyword she responds and dumps.
i cant.
gives meCode:cout << "Enter Comment: ";
getline(cin,userInput);
Code:-------------------Configuration: RoDBoT - Win32 Debug--------------------
Compiling...
RoDBoT.cpp
C:\Program Files\Microsoft Visual Studio\MyProjects\RoDBoT\RoDBoT.cpp(234) : error C2780: 'class std::basic_istream<_E,_Tr> &__cdecl std::getline(class std::basic_istream<_E,_Tr> &,class std::basic_string<_E,_Tr,_A> &,const _E)' : expects 3 argument
s - 2 provided
c:\program files\microsoft visual studio\vc98\include\string(149) : see declaration of 'getline'
C:\Program Files\Microsoft Visual Studio\MyProjects\RoDBoT\RoDBoT.cpp(234) : error C2784: 'class std::basic_istream<_E,_Tr> &__cdecl std::getline(class std::basic_istream<_E,_Tr> &,class std::basic_string<_E,_Tr,_A> &)' : could not deduce template a
rgument for 'class std::basic_string<_E,_Tr,_A> &' from 'char [256]'
Error executing cl.exe.
RoDBoT.obj - 2 error(s), 0 warning(s)
but elsewhere in my program
works fine....been a long day in bot hell.Code:cout << "Please enter your name: ";
getline(cin,name);
oops, wasn't being descriptive enough, try this
Code:cin.getline(userInput, 256, '\n');
nope that way it prompts and immeadiatly ends...
new discovery, consider this code:
Code:void Conversation::prompt()
{
cout << "Enter Comment: ";
cin >> userInput;
/* Convert entire character array
to lowercase. Thanks to Travis Dane for
the for..loop idea.
*/
for (int i = 0; i < strlen(userInput); i++)
{
userInput[i] = tolower(userInput[i]);
}
convo();
}
/* Function: covo
Purpose: This is where all the magic happens!
*/
void Conversation::convo()
{
/* Big thanks to eibro for getting
me going with this section,
without his help rodbot would ve
a total dumbass.
*/
ifstream compareFile("comp.txt");
ifstream lookupFile("ans.txt");
if (compareFile.fail())
{
cout << "Fatal Error: Missing comp.txt and/or ans.txt!\n";
}
else if (lookupFile.fail())
{
cout << "Fatal Error: Missing comp.txt and/or ans.txt!\n";
}
string place_hold;
int indexNum;
while (getline(compareFile, place_hold))
{
stringstream format;
format << place_hold;
format >> indexNum >> place_hold;
if (userInput == place_hold)
{
int compareNum;
string compareString;
while (getline(lookupFile, compareString))
{
stringstream convert;
convert << compareString;
convert >> compareNum;
getline(convert, compareString);
if (compareNum == indexNum)
{
cout << compareString << endl;
prompt();
}
/*
else
{
cout<<"bhb\n";
prompt();
}
*/
}
}
}
}
now like that anytime u enter a keyword it works....now modify the lower if to this:
now it only works if u enter the keyword hi, the first keyword in comp.txt, so why is the else making it stop looking after line 1?Code:if (compareNum == indexNum)
{
cout << compareString << endl;
prompt();
}
else
{
cout<<"bhb\n";
prompt();
}
heres the cpp...
Then you should install error handlers that handle errors inQuote:
Originally posted by RoD
getting the error handling is giving me errors im having trouble handling :P
error handlers...
ok i'm getting somewhere, the else is throwing it off becuz it loops until they are ==, and if on pass one they arent it hits the else....
How about introducing yourself first.. like a nice and polite robot...
and asking the user/stranger their info like you r doing a real conversation instead of being a regular commanding computer..
eneter your name... bla.. bla.... if you have intention to make it a sex toy... then its different case.... :D:O;)
Hmmm, I don't think the algorithm I gave you is going to work.
Okay, I should have did this the first time around... but here goes.
[list=1][*]Get user input[*]Open conversation file and search for the word(s?) entered by the user.[*]Record the index number if an entry was found, else, print a default message (eg. "Take off your pants") and goto step 1[*]Open up answers file and search for the desired index number, if it's found, print the cooresponding string, else print a default message.[*]Goto step 1[/list=1]
The only thing I see as a problem is step 2... the user isn't going to enter a single word response so we're going to need to search for each word in the conversation file. For each response found, push the index number onto a vector. If a response isn't found, push a predetermined value onto your vector (like 0). Finally, iterate through the vector and find the index number which occoured the most frequent. Search for a response in the answers file with this index. Print, and go to step 1.
I'll help you out with this tommorow. I suggest breaking it up into classes/objects (answer, response, index, bot, etc.)
ok thnx eibro, i wiped out the convo function last night.
>>How about introducing yourself first.. like a nice and polite robot...
and asking the user/stranger their info like you r doing a real conversation instead of being a regular commanding computer..
what are u talkin bout??? so i guess it doesnt count when he takes in name/age/sex then tells his name/age/sex?? did u use it at all??
So tell me, When you first meet a person you askQuote:
Originally posted by RoD
what are u talkin bout??? so i guess it doesnt count when he takes in name/age/sex then tells his name/age/sex?? did u use it at all??
"Name? Age? Sex?" ?
>>So tell me, When you first meet a person you ask
"Name? Age? Sex?" ?
nowadays asking the sex may be a good idea...
>>nowadays asking the sex may be a good idea...
So, do you introuduce yourself first or ask somebody to introduce him/herself first...???
>> Enter you name:... Enter your.. bla bla...
or..
Hey what's up?? My name is Rod.. I'm bla bla... And what's you's
which sounds better and more normal...???
:):)
i'll add to the list.
if i can find a way to stop the loop, set a false/true, then exit to an if to check state i'll be ok. I had tried getting length of the file and running it till it was eof, then setting state, but to no avail. Does anyone have a suggestion?Code:while(userInput != "goodbye")
{
while (getline(check, temp))
{
stringstream format;
format << temp;
format >> index >> temp;
if (userInput == temp)
{
while (getline(answr, comparestring))
{
stringstream convert;
convert << comparestring;
convert >> comparenum;
getline(convert, comparestring);
if (comparenum == index)
{
cout << comparestring << endl;
user();
}
}
}
}
}