I am working on a program to help make a small "dictionary" for our robot project ( see Practice Speaking English for more detail ).
The purpose for this small program is read in a word and its meaning which are provided in word.txt and meaning.txt. Then the program will convert it to the requested form for our robot.
This is the screen result:Code:#include <iostream> #include <fstream> using namespace std; int main() { ifstream input; input.open("word.txt"); if (input.fail()) { cout<<"File doesn't exist."<<endl; system("pause"); return 0; } ofstream output; output.open("output.txt"); char word[80]; char meaning[200]; input>>word; cout<<word<<endl; input.close(); input.open("meaning.txt"); if (input.fail()) { cout<<"File doesn't exist."<<endl; system("pause"); return 0; } while (!input.eof()) { input.getline(meaning, 200, '.'); cout<<meaning<<endl; } input.close(); cout<<"Copying....."<<endl; output<<meaning<<endl; output<<"<category>"<<endl; output<<"<pattern> WHAT IS THE MEANING OF "<<word<<" </pattern>"<<endl; output<<"<template><random>"<<endl; output<<"<li> Its meaning is "<<meaning<<".</li>"<<endl; output<<"<li> It means "<<meaning<<".</li>"<<endl; output<<"<li> It is "<<meaning<<".</li>"<<endl; output<<"</random></template>"<<endl; output<<"</category>"<<endl; output<<"<category>"<<endl; output<<"<pattern> WHAT DOES "<<word<<" MEAN </pattern>"<<endl; output<<"<template><srai> WHAT IS THE MEANING OF "<<word<<" </srai></template>"<<endl; output<<"</category>"<<endl; cout<<"done!"<<endl; system("pause"); return 0; }
So it seems my getline works to get the sentence. but when I try to output to the txt file output.txt. The problem occurs:AIML
he is good
Copying.....
done!
Press any key to continue . . .
The meaning sentence didn't output! Therefore, I don't know why the getline get the meaning but can't output it! THX!
<category>
<pattern> WHAT IS THE MEANING OF AIML </pattern>
<template><random>
<li> Its meaning is .</li>
<li> It means .</li>
<li> It is .</li>
</random></template>
</category>
<category>
<pattern> WHAT DOES AIML MEAN </pattern>
<template><srai> WHAT IS THE MEANING OF AIML </srai></template>
</category>