Apr 1, 2009 at 12:48am UTC
Hello everyone I just joined here.
I have a question regarding a project I've been working on.
I have the following code:
cout << "\nISBN:";
cin.getline(isbn, MAX_ISBN);
cout << "\nTitle:";
cin.getline(bookTitle, MAX_TITLE);
cout << "\nAuthor:";
cin.getline(author, MAX_AUTHOR);
cout << "\nPublisher:";
cin.getline(publisher, MAX_PUBLISHER);
cout << "\nDate Added:";
cin.getline(dateAdded, MAX_DATE);
cout << "\nQuantity-On-Hand:";
cin.getline(qtyOnHand, MAX_ROW);
cout << "\nWholesale Cost:";
cin.getline(wholesale, MAX_ROW);
cout << "\nRetail Price:";
cin.getline(retail, MAX_ROW);
I have all of the array and array sizes in my header:
//Define array sizes
#define MAX_ROW 20
#define MAX_TITLE 51
#define MAX_ISBN 14
#define MAX_AUTHOR 31
#define MAX_PUBLISHER 31
#define MAX_DATE 11
//Define arrays for bookInfo
char bookTitle[MAX_ROW][MAX_TITLE];
char isbn[MAX_ROW][MAX_ISBN];
char author[MAX_ROW][MAX_AUTHOR];
char publisher[MAX_ROW][MAX_PUBLISHER];
char dateAdded[MAX_ROW][MAX_DATE];
int qtyOnHand[MAX_ROW];
double wholesale[MAX_ROW];
double retail[MAX_ROW];
I also have the #include ".cpp" in my header.
I am getting this error message on all of my cin.getlines:
cannot convert parameter 1 from 'char [20][11]' to 'char *'
Why am I getting this error and how do I fix it? Any help would be appreciated.
Apr 1, 2009 at 2:09am UTC
basically, you are tying to assign data meant for a one dimensional array two a two dimensional array. If you are only keeping one record, i seems all you need is char bootTile[MAX_TITLE]
, but if you are keeping MAX_ROW of each, the best way is probably to make an array of structure called BookInfo or something with all your information as members.
Apr 1, 2009 at 2:55am UTC
cin.getline(qtyOnHand...
cin.getline(wholesale...
cin.getline(retail...
Doesn't the first parameter for getline have to be char* or char[] ?
What's the best way to read numeric with getline?
Just use:
cin >> qtyOnHand[i]; // ?? or...
?