-
April 30th, 2009, 10:58 AM
#1
can someone help please
void createArchivoList(ifstream& infile, librarybookLista& bookList);
void displayMenu();
int main()
{
librarybookLista bookList;
int choice;
char ch;
string title;
ifstream infile;
//open the input file
infile.open("a:\\libreria.txt");
if(!infile)
{
cerr<<"Input file does not exist"<<endl;
createArchivoList(infile, bookList);
return 1;
}
//create the video list
//createArchivoList(infile, bookList);
infile.close();
displayMenu(); //show the menu
cout<<"Enter your choice: ";
cin>>choice;
-------------------------------------------------------------------
compile answer:
Input file does not exist
Why do the compili do not goes to th functions createArchivoList(infile, bookList); ?
-
April 30th, 2009, 11:00 AM
#2
Re: can someone help please
Presumably it can't find the file you want to read.
-
April 30th, 2009, 11:22 AM
#3
Re: can someone help please
Are you sure that it does not go into the createArchivoList function ?
Do you have a cout/cerr statement at the start of the routine ?
Just a guess ... it is going into the function, but all the file access
statements fail ... because the internal state of the file stream
object is "fail/false".
Try the following to clear the internal flags ...
Code:
if(!infile)
{
cerr<<"Input file does not exist"<<endl;
infile.clear(); // add this line
createArchivoList(infile, bookList);
return 1;
}
-
April 30th, 2009, 12:51 PM
#4
Re: can someone help please
This is the function I try the code and still I have the same logic error//infile.clear(); // add this line
void createArchivoList(ifstream& infile, librarybookLista& bookList)
{
string Title;
string autor1;
string autor2;
string editora1;
string editora2;
string ProductionCo;
char ch;
int InStock;
library newBook;
getline(infile, Title);
while(infile)
{
getline(infile, autor1);
getline(infile, autor2);
getline(infile, editora1);
getline(infile, editora2);
getline(infile, ProductionCo);
infile>>InStock;
infile.get(ch);
newBook.setBookInfo(Title,autor1,autor2,editora1,
editora2,ProductionCo,InStock);
bookList.insertFirst(newBook);
getline(infile, Title);
}//end for
}//end createArchivoList
-
April 30th, 2009, 12:53 PM
#5
Re: can someone help please
libreria.txt the file exist in the same folder
-
April 30th, 2009, 01:05 PM
#6
Re: can someone help please
I don't understand why you're trying to call createArchivoList in the if statement when you've failed to open the file. Wouldn't it make more sense to call it in the other case?
-
April 30th, 2009, 01:49 PM
#7
Re: can someone help please
I think I misunderstood your problem. I thought that createArchivoList()
created the file if it did not exist.
You are explicitly saying the file exists on the a:\\ drive. Is this the case?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|