i'm stuck

ok i'm stuck at a place i can't think and figure out.
is more like a auto reply thing.
when i key in a question, it suppose to answer me back with an answer that is stored within a file.txt. if question doesn't meet whats in the file.txt, it will just reply back I do not have and answer to it.

file format
[question];[answer]
Hi;Welcome to use the system
Whats your name;I'm just a system

so now i need to know how or anyone can provide the coding on how to make this part to work. Please people, please help me =)
I suggest you reading and storing questions and answer in a map.
In order to read them you can use getline

eg:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//Declare the map
map<string,string> QA;

//Get a question and an answer
ifstream file("yourfile");
string key, value;
getline(file,key,';');//read the key until a semicolon is found
getline(file,value);
QA[key] = value;//set the values

//Display the answer corresponding to a given question
map<string,string>::iterator i = QA.find(question);
if ( i != QA.end() )
   cout << QA[question];
else
   //Question doesn't exists 
That's the best approach, but you don't need an iterator if none of your answers are blank.

1
2
3
4
5
string answer = QA[question]
if ( answer.empty() )
   //Question doesn't exists
else
   cout << answer; 
Topic archived. No new replies allowed.