amarwhey
February 25th, 2006, 09:44 AM
Hi ive written the following bit of code BUT on execution it seems to jump from line 4 all the way to line 9, without accepting user input. The function to be called is also shown. If however i replace line 5 with a cin>>, it works, but i need to be able to read a whole line not just one string, any ideas???
1: cout <<"Please type the verb in your sentance: "<< endl;
2: cin >> verbStr;
3 verbOutStream << verbStr << endl;
4: cout <<"What should the response be?: ";
5: useFunc.readLines( cin, telMe );
6: nounVerbStr = nounStr + space + verbStr;
7: phraseOutStream << nounVerbStr <<endl;
8: phraseOutStream << telMe << endl;
9: cout <<"Phrase added";
10: }
11: else
12: {
13: cout << phrasePair[nounVerbStr];
14: }
15: }
The function im trying to call:
void BOT::readLines( istream & in, string & s )
{// a function to replace getLine() because there was a bug in Visual Studio C++ 6 and you don't know whether
// the patch was applied.
char c;
s.erase(); // clear the old string
c = in.get(); // read one character ahead
while ( c!='\n' )
{// not end of line
s = s + c; // add the string
c = in.get(); // read the next character
}
}
The output:
What should the response be?Phrase added
It should be:
What should the response be? <accept user input "Yes i am fine\n">
Phrase added
Hope som1 can help!!!!!
thanks in advance!!!
Amar!!
1: cout <<"Please type the verb in your sentance: "<< endl;
2: cin >> verbStr;
3 verbOutStream << verbStr << endl;
4: cout <<"What should the response be?: ";
5: useFunc.readLines( cin, telMe );
6: nounVerbStr = nounStr + space + verbStr;
7: phraseOutStream << nounVerbStr <<endl;
8: phraseOutStream << telMe << endl;
9: cout <<"Phrase added";
10: }
11: else
12: {
13: cout << phrasePair[nounVerbStr];
14: }
15: }
The function im trying to call:
void BOT::readLines( istream & in, string & s )
{// a function to replace getLine() because there was a bug in Visual Studio C++ 6 and you don't know whether
// the patch was applied.
char c;
s.erase(); // clear the old string
c = in.get(); // read one character ahead
while ( c!='\n' )
{// not end of line
s = s + c; // add the string
c = in.get(); // read the next character
}
}
The output:
What should the response be?Phrase added
It should be:
What should the response be? <accept user input "Yes i am fine\n">
Phrase added
Hope som1 can help!!!!!
thanks in advance!!!
Amar!!