So I have writing to a file and reading from a file. Now I need to be able to find specific data that was previously entered and saved to that certain file. Here is the code I have so far.

{
	ofstream myFile ("words.txt");
	if (myFile.is_open())
	{
		myFile << dictionary.newWord();
		myfile.close();
	}
	else cout << "Cannot open file";
	}

	{
		string word;
		ifstream myFile ("words.txt");
		if (myFile.is_open())
		{
			while (! myFile.eof() )
			{
				getWord (myFile,word);
				cout << word << endl;
			}
			myFile.close();
		}
		else cout << "Cannot open file";

That doesn't tell much. Appears like the program is just writing one word to the file then attempting to read it back. The open() statement you have will erase everything that's already in the file. If you want to add more words every time you run the program then you have to use ios::ate as the second parameter in that open() statement. ofstream myFile ("words.txt", ios::ate);

So for reading the text file do I have to do the same thing?

example:

ifstream myFile ("words.txt", ios::ate);

Like that? Or is there something different?

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.