I am working on a project for my c++ class and although my code looks fine to me (a beginner) whenever I run it I get error C2065 undeclared identifier in almost every line. I have done my research and have a feeling it has something to do with using namespace std; but I am not sure. Any help would be greatly appreciated.
The project is to create a vector that store a book list and then offer the user the ability to add a book to the list, display the list using an iterator, remove a book using an iterator, or store the data in an external file. Here is what I have so far:
#include <iostream>
#include <vector>
#include <string>
#include "bookColl.h"
#include <algorithm>
#include <fstream>
using namespace std;
int main()
{
vector <string> bookCollection;
string book1, book2, book3;
cout << "Enter the first book in your book collection: " << endl;
getline(cin, book1);
cout << "\nEnter the second book in your book collection: " << endl;
getline(cin, book2);
cout << "\nEnter the third book in your book collection: " << endl;
getline(cin, book3);
bookCollection.push_back(book1);
bookCollection.push_back(book2);
bookCollection.push_back(book3);
vector <string> ::iterator myITER;
vector <string> ::const_iterator cITER;
double decide;
do
{
int choice = 0;
cout << "What would you like to do?/n1.Add a book to your collection." <<
"/n2.Display your book collection." << "/n3.Remove a book from your collection" << "/n4. Stop adding books and store the data in an external file" << "/nChoose a number 1 through 4: " << endl;
if (choice == 1)
{
string addNew;
addBook(&addNew);
bookCollection.push_back(addNew);
}
else if (choice == 2)
{
cout << "Here are your books: " << endl;
for (cITER = bookCollection.begin(); cITER != bookCollection.end(); cITER++)
{
cout << *cITER << endl;
}
}
else if (choice == 3)
{
int removeBook;
myITER = bookCollection.erase(bookCollection.begin() + removeBook);
cout << "enter the numbered book position for the book you would like to remove: " <<
"/n(The books in your book collection are labels for 0 up)" << endl;
cin >> removeBook;
cout << *myITER << endl;
}
else if (choice == 4)
{
sort(bookCollection.begin(), bookCollection.end());
ofstream bookFile;
bookFile.open("BookCollection.txt", ios::out | ios::app);
bookFile << " This is a line of text. \n";
bookFile << " This is a second line of text. \n";
bookFile.close();
}
cout << "\nWould you like to run this program again? If so select 1 for Yes, and 0 for No" << endl;
cin >> decide;
} while (decide > 0);
}
bookColl.h
string addBook(string* pValOne);
bookColl.cpp
#include <iostream>
#include <vector>
#include <string>
#include "bookColl.h"
using namespace std;
string addBook(string* pValOne)
{
string newBook;
*pValOne = newBook;
cout << "What is the name of the book you would like to add?" << endl;
getline(cin, *pValOne);
return newBook;
}