I am writing a program that basically works like Project Gutenberg. What this does is it takes plain text files as input and outputs these text files in HTML format. I am just beginning the project and have started by trying to extract the title from a file. What I know is that the title ALWAYS begins with "Title:" and only lasts the line that "Title:" is on. I have written code but it doesn't work (of course, that's why I came here!"). To me, my code seems logically correct but it just doesn't run. Any help would be appreciated.
getTitle() function:
Code:
string Book::getTitle(string title)
{
size_t pos;
pos = title.find("Title:");
title = title.substr(pos);
if(title.find("Title:"))
{
return title;
}
else
return "";
}
Process book to store title in variable:
Code:
Book::Book(std::istream& in)
{
std::string title, line;
string::size_type start = 0;
getline(in, line);
while(in)
{
if(title[start] == ' ')
{
getline(in, line);
}
else
{
title = getTitle(line);
break;
}
}
}