I'm somehow messing up opening a file and making a c-style filename
Expand Post »
The following code is part of a program to document the book in my house, like those things they have at public libraries. I learned about minupulating files in programs last night and have many errors in this program.
First, the c-style string for filename comes out as - filename.txt" instead of without the quote
And even if you try running my program with a default filename like newbook it turns out to fail.
Book::Book(string Title,string AuthorLastName,string AuthorFirstName,string PublishingCompany,int SeriesNumber,int NumPages,int CopyrightYear,string Series):
m_Title(Title),
m_Series(Series),
m_AuthorFirstName(AuthorFirstName),
m_AuthorLastName(AuthorLastName),
m_PublishingCompany(PublishingCompany),
m_SeriesNumber(SeriesNumber),
m_NumPages(NumPages),
m_CopyrightYear(CopyrightYear)
{
fstream filehandle;
string filename=m_Title+".txt";
char m_filename[80];
for(int i=0;i<filename.size();++i)
{
m_filename[i]=filename[i];
}
//the c-style string should end with a '\0',
//so add line m_filename[i] = '\0';
//define i out of the for statement
cout<<m_filename;
filehandle.open(m_filename);
// the simplest way is to use filehandle.open(filename.c_str());
}
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.