I am trying to get a program to work for an assignment, but I can't seem to get anywhere else on it. The purpose of the program is to find a specific verse in the Bible by reading a given txt file. I'm really not sure where I went wrong, as the compiler errors tell me "no known conversion". Any assistance would be greatly appreciated.
#include <iostream>
#include <fstream>
usingnamespace std;
int main() {
string s; // For reading in words
string filename; // For specifying a file name
ifstream in; // Input file stream
ofstream out; // Output file stream
string book;
int chapter;
int verse;
bool chapck=0;
bool vrsck=0;
bool bkck=0;
// For keeping track of the number of words in the file
cout << "Please enter a book in the Bible";
cin >> book;
cout << "Please enter the number of a chapter in the book";
cin >> chapter;
cout << "Please enter a verse number in the chapter";
cin >> verse;
// open the input file
in.open("Bible.txt");
if (!in.is_open()) {
cout << "Error opening file " << filename << ". Exiting ....." << endl;
return 1;
}
while(!in.eof()){
//while loop needs verified
//start getting characters from Bible.txt
getline(in,s);
//if statements verifying each of book, chapter, verse
if (bkck ==0)
if (s== ("THE BOOK OF " && book))
bkck=1;
if (bkck ==1 && chapck ==0)
if (s== "CHAPTER " && chapter)
chapck=1;
if (bkck ==1 && chapck ==1)
if (s== verse)
vrsck=1;
if (bkck ==1 && chapck ==1 && vrsck ==1)
cout<<s;
}
return 0;
}
To answer my question determine what is the type of expression
("THE BOOK OF " && book)
and what is the type of the left ooperand s before operator ==.
As far as I know there was a proposal to the C++ Standard to introduse an operator that converts an object of type std::string to bool. However at present there is no such an operator in class std::string.
The intention was that it would read that line to find both "THE BOOK OF" and the book name, as the txt file has "THE BOOK OF JOHN" for example, on its own line. Do you have a suggestion for another way I could go about checking for the book/chapter/verse?
@ vlad from moscow
From what I know, wouldn't you want to make a switch statement for your beginning if statements, then put the secondary if statements in each switch ? To me it would look cleaner, but I would not know how to make the switch statement have multiple inputs.