#include <iostream>
#include <string>
#include <fstream>
usingnamespace std;
void chckstr ()
/*
gets the next word from input.txt,
checks that its between 3 and 6 letters
if so, writes the word to output.txt
*/
{
string line;
ifstream readfile ("input.txt");
ofstream writefile ("output.txt", ios::in|ios::binary|ios::ate); //I don't know what ios::in etc. means...
if ((readfile.is_open())&&(writefile.is_open()))
{
while (! readfile.eof() )
{
getline (readfile,line);
if ((!(line.empty()))&&(line.size() <= 6) && (line.size() >=3))
{
cout << "pass:" << line << endl; // display that this word should be written
writefile << line << endl; //write this word to output.txt (this is my problem)
}
else
{
cout << "fail:" << line << endl; //otherwise show that it isnt being written
}
}
readfile.close(); //close the filestreams
writefile.close();
}
else cout << "Unable to open file";
}
int main ()
{
// declaring variables:
system ("CLS"); //this will clear the screen of any text from prior run
cin.clear(); //this will clear any values remain in cin from prior run
// process:
chckstr ();
// terminate the program:
system ("PAUSE");
return 0;
}
The outputting to console is working like a dream, I see all the words that should be written and the ones that shouldn't... but I still have an empty output.txt file :(