Hi everyone,
I have a program that is like a media library and has the user input titles, authors, etc. for books or recordings. What I have works so far, but when you input something with a space it breaks it up and only saves the first word. I looked it up and tried multiple things like cin.get(), but I couldn't make it work because the length is user-defined. I also tried getline() which gives me a red squiggly line saying "Error: no instance of overloaded function "getline" matches the argument list". I know using strings would fix this problem, but I was instructed to use char arrays. Here is my code:
I bolded the areas that I'm talking about. Let me know if you need to see the classes/headers, although I don't think those are the problem.Code:#include <iostream> #include <string> #include "holding.h" #include "book.h" #include "recording.h" using namespace std; Holding* holdFunction(){ char* title; title = new char; char* performer; performer = new char; char* author; author = new char; char format; char type; int callNumber; cout << "Enter B for book, R for recording: "; cin >> type; switch(type){ case 'B' : { cout << "Enter book title: "; cin >> author; cout << endl << "Enter book author: "; cin >> author; cout << endl << "Enter call number: "; cin >> callNumber; Book* book = new Book(title,callNumber,author); return book; break; } case 'R' : { cout << "Enter recording title: "; cin >> title; cout << endl << "Enter performer: "; cin >> performer; cout << endl << "Enter format: (M)P3, (W)AV, (A)IFF: "; cin >> format; cout << endl << "Enter call number: "; cin >> callNumber; Recording* record = new Recording(title,callNumber,performer,format); return record; break; } default: cout << "You entered an invalid type!" << endl; return NULL; } } int main(){ Holding* arr[5]; cout << "Enter holdings to be stored in a list:" << endl << endl; for(int i = 0; i < 5; i++){ arr[i] = holdFunction(); } cout << "Here are the holdings:" << endl << endl; for(int i = 0; i < 5; i++){ arr[i]->print(cout); } cin.get(); return 0; }
Thanks for any help!!
-Ryan



LinkBack URL
About LinkBacks



