1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
using namespace std;
int main(){
// Declare Vairables
bool bookFound = true;
bool chapterFound = true;
string line;
string bookName;
string chapter, verse;
ifstream in;
ofstream out;
// Opens the file
in.open("bible.txt");
if (in==0)
{
cerr << "Error! File not found" << "\n";
exit(1);
}
//open (verses.txt & test)
//ask input
cout << "Please enter reference of the verse you would like to retrieve." << "\n";
cout << "Book: " ;
in > getline(cin, bookName);
cout<< "\n" << "Chapter: " ;
cin >> chapter;
cout << "\n" << "Verse: ";
cin >> verse;
// Convert the Book Name to Capital letters
for (int i = 0; i < bookName.size(); i++)
bookName[i] = toupper(bookName[i]);
// Search the Book
getline(in,line, '\n');
while(bookFound == false && in.eof() == false)
{
if(line.substr(0, 11) == "THE BOOK OF")
{
if(line.substr(12, bookName.size()) == bookName)
{
bookFound = true;
getline(in,line);
}
}
else
cout << bookName << " not found.";
}
if(bookFound == true) // Looks to see if the book is true
{
while(chapterFound == false && in.eof() == false)
{
if (line.substr(0,7) == "CHAPTER")
{
if(line.substr(8, chapter.size()) == chapter)
{
chapterFound = true;
getline(in,line, '\n');
}
else
cout << "Chapter " << chapter << " not found.";
}
}
}
if(chapterFound == true)
{
if (line.substr(0,1) == verse)
{
size_t found = line.find_first_not_of("abcdefghijklmnopqrstuvwyz.[] "); // looks for the next number to stop at
cout << line.substr(0, found);
out.open("verses.txt", ios::app); // should create a file to store the output
out << line; // should store the information into the file ^^
}
else
cout << "Invalid verse number";
}
}
| |