Sign in to follow this  

std::fstream problem?

This topic is 4415 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Well, i have some code that gets all the files in a folder, and goes thru them one at a time and loads data for files. But for some reason, it will read the first file ok, but not the second. It says that the file is opened but it never reads it. It messes up at the while (std::getline(File, Input);
BOOL cWindow :: LoadFolder(std::string Folder)
{
	std::string Result = "";
	std::string Input = "";
	int Read = 0;
	std::fstream File;
	std::ostringstream oss;
	cButtonA *atr;
	CFileSearch *Search = new CFileSearch(Folder + "*.txt");

	while(Search->GetNext(Result))
	{
		oss << Folder << Result;

		File.open(oss.str().c_str(), std::ios::in);
		
		if  (File.is_open())
		{
			while (std::getline(File, Input))
			{
				if (Input == "!!BUTTON!!")
				{
					atr = new cButtonA();

					if (!ReadButton(atr,File,Read))
					{
						delete atr;
						return Read;
					}

					AddButton(*atr, Folder);

					delete atr;
				}
			}
		}
		else
		{
			File.close();
			return NOFILE;
		}

		oss.str("");
		File.close();
		Input = "";
	}

	delete Search;

	return SUCCESS;
}


Jake

Share this post


Link to post
Share on other sites
From the a very brief glance of the code i don't see anything obvious so i'm going to take a stab in the dark and say call std::basic_ios::clear method after you've closed a file stream and before re-opening again. There is a known issue about iostream states not being reset after a file stream has been closed and reopened again.

Share this post


Link to post
Share on other sites

This topic is 4415 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this