std::fstream problem?

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 = "";
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();

{
delete atr;
}

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

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

delete Search;

return SUCCESS;
}


Jake

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.

thx it worked :D

Jake

Create an account

Register a new account

• Forum Statistics

• Total Topics
627718
• Total Posts
2978793

• 9
• 9
• 21
• 14
• 12