Thanks to your help,
I was able to figure out why,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main ()
{
string word;
char definition;
cout<<"Please give word"<<endl;
cin>>word;
cout<<"And it's definition?"<<endl;
cin>>definition;
ofstream myfile ("dic.txt");
if (myfile.is_open())
{
myfile<<word<<'\t'<<definition;
myfile.close();
}
else cout<<"Unable to open file";
system ("PAUSE");
return 0;
}
|
wasn't sending the entire string, "definition," to the file.
I have since rewritten it,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main ()
{
string word, definition;
ofstream myfile ("dic3.txt");
if (myfile.is_open())
{
cout<<"Please enter word: ";
getline(cin,word);
cout<<"Please enter its definition: ";
getline(cin,definition);
myfile<<word<<'\t'<<definition;
myfile.close();
}
else cout<<"Unable to open file";
system ("PAUSE");
return 0;
}
|
But have ran into a new problem, every time I run the program it erases all of the previous information.
For example, file dic.txt might read:
Book '\t' A collection of pages
|
Until I run the program again, then it's replaced with the new data. How can I keep this from happening, so with time more entries are saved? And how might I make it alphabetize the entries?
Also, why/how is "cin" lacking in security?