Tasked with creating a code to read in a file of books and their respective authors, organizing the information into two arrays and outputting. The arrays and functions are necessary elements of the assignment. Still not adept at understanding debug issues. Assistance, as always, is greatly appreciated. The errors are pointer issues (I think) during the infile.get commands.
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
|
#include<iostream>
#include<string>
#include<fstream>
using namespace std;
const int ARRAY_SIZE = 1000;
string bookTitle[ARRAY_SIZE];
string bookAuthor[ARRAY_SIZE];
int loadData(string pathname);
void showAll(int count);
int main() {
string pathname;
cout << "Please enter the directory location of the file you'd like to organize: "
<< endl;
cin >> pathname;
int count = loadData(pathname);
showAll(count);
getchar();
return 0;
}
int loadData(string pathname)
{
int index;
ifstream infile;
infile.open(pathname);
if (infile.good()) {
while(!infile.eof()) {
infile.get(bookTitle, ' ');
infile.get(bookAuthor, ' ');
index++;
}
} else {
index = -1;
}
return index;
}
void showAll(int count) {
for(int i = 0; i < count; i++) {
cout << bookTitle[i] << " "
<< "(" << bookAuthor[i] << ")"
<< endl;
}
}
|
The error messages are:
documents\visual studio 2010\projects\hw9 10\hw9 10\library i.cpp(41): error C2664: 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::get(_Elem *,std::streamsize)' : cannot convert parameter 1 from 'std::string [1000]' to 'char *'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\users\documents\visual studio 2010\projects\hw9 10\hw9 10\library i.cpp(42): error C2664: 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::get(_Elem *,std::streamsize)' : cannot convert parameter 1 from 'std::string [1000]' to 'char *'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast