V
Venkat
Hi All,
Can someone tell why the program is crashing in the call to Fun2. I could
able to create the filename, write into it and read it in Fun1 but the same
file if i open in Fun2 it is crashing. Is something that needs to be done to
NewFile object like destroying it, if so can someone tell how to do that. I
used ~NewFile() but it is throwing syntax error.
void main()
{
Fun1(filename);
Fun2(filename);
}
void CINSTALL :: Fun1(const std::string filename)
{
fstream NewFile;
if(!NewFile)
{
//prints error
}
NewFile.Open(filename.c_str(), ios:ut);
//Now i write into the file.
....
....
//Now i can read the new file contents.
......
//I close the file
NewFile.close();
}
void INSTALL :: fun2(const std::string &fileName)
{
const char* fn = fileName.c_str();
int size = fileName.length();
std::string file = "";
for ( int i = 0; i < size; i++ )
{
if ( fn == '\\' )
file += "\\\\";
else
file += fn;
}
ifstream _istream;
_istream.open(file.c_str()); //This statement is failing and the program
is getting crashed.
if(_istream)
{
}
}
Can someone tell why the program is crashing in the call to Fun2. I could
able to create the filename, write into it and read it in Fun1 but the same
file if i open in Fun2 it is crashing. Is something that needs to be done to
NewFile object like destroying it, if so can someone tell how to do that. I
used ~NewFile() but it is throwing syntax error.
void main()
{
Fun1(filename);
Fun2(filename);
}
void CINSTALL :: Fun1(const std::string filename)
{
fstream NewFile;
if(!NewFile)
{
//prints error
}
NewFile.Open(filename.c_str(), ios:ut);
//Now i write into the file.
....
....
//Now i can read the new file contents.
......
//I close the file
NewFile.close();
}
void INSTALL :: fun2(const std::string &fileName)
{
const char* fn = fileName.c_str();
int size = fileName.length();
std::string file = "";
for ( int i = 0; i < size; i++ )
{
if ( fn == '\\' )
file += "\\\\";
else
file += fn;
}
ifstream _istream;
_istream.open(file.c_str()); //This statement is failing and the program
is getting crashed.
if(_istream)
{
}
}