I intially get this program working using getline, however, I need to search for a certain character in a line of text and reaplce it with another. The program is supposed to prompt a user to input a question(which is ignored) and will then read a 1 line "answer" from a text file that contains 8 different 1 line answers. After the first and with each subsequent answer, the user is prompted if they want to ask another question. I have it working where it will read the first line from the text file, however, the program stops there.
Any assistance would be appreciated.
Thanks
The text file looks like:Code:#include <fstream> #include <iostream> #include <cstdlib> using namespace std; using std::ifstream; newLine(ifstream& inStream); const int NUMBER_OF_CHAPTERS=20; int main() { char doesntmatter[100]; char question=0; int number_of_answers=0; ifstream inStream; do { inStream.open("A:\\answerfile.txt"); cout<<"Please enter a question:"<<endl; cin.getline(doesntmatter, 100, '\n'); char next; inStream.get(next); while (! inStream.eof()) { while(next != '\n') { if(next=='#') cout<<NUMBER_OF_CHAPTERS; else cout<<next; inStream.get(next); } } cout<<"Would you like to ask another question, y or no:"<<endl; cin>>question; cin.ignore(); number_of_answers++; if(number_of_answers==7) { inStream.close(); inStream.open("A:\\answerfile.txt"); } }while(question=='y'||question=='Y'); return 0; }
Test answer number #.
This is another test answer.
This is yet another test answer.
This is even yet another test answer.
This is test answer number five.
This is test answer number six.
This is test answer number seven.
This is test answer number eight.



LinkBack URL
About LinkBacks


