Hello I figured out my other problem, now left with another 2. One which I beleive is a logic error since if I enter A it will output AA but I cant seem to solve that one.

Also the other is that I'm using app (append). How can I delete the contents of the file when its no longer needed?

void hangman::writefile(char ch)
{
 textfile = ch;

	ofstream outfile; //writes to txt
	outfile.open("new.txt", ios::app);

	if (outfile.fail())
		{
			cerr << "error";
			exit(1);
		}
	
		else
		{
			outfile << textfile;
		}

		outfile.close();
}

here the code for the outstream buffer...

and now heres the code for the instream buffer...

void hangman::readfile()
{
	ifstream infile ; // reads from txt
	infile.open("new.txt");

		if (infile.fail())
			{
			cerr << "Error";
			exit(1);
			}
		else       
			while( ! infile.eof() )
			{	
			cout << textfile;
			infile >> textfile;
			
			} 

			infile.close();

}

I'm 100% certain the problem lies :

while( ! infile.eof() )
			{	
			cout << textfile;
			infile >> textfile;
			
			}

but I cant figure out how to correct it. if i move cout under the infile i get 2 of the last entires the same, if i leave it as it is i get 2 of the first ones........any ideas?

John

[post=155265]This[/post]?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.