Class/Vector memory question

Hi all

I have this program for class that involves creating an array of classes. For some reason i get an "Access violation reading location 0xddddddd1.". The code compiles correctly and i know that the data file is being read (although it may not be being read correctly, but that is a different post). I have this bad feeling that the book class isn't being over written correctly? any thoughts or comments would be greatly appreciated.
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
vector<bookData> createArray(int numOBook) 
{
	vector <bookData> vecBooks;
	
ifstream data("dataFile.dat");
	numOBook--;
	cin.clear();
	bookData book;
	if (!data.good())
	cout<<"error opening file."<<endl;
	else
	{
		while(data.good())
		{
			
		for(int x=0;x<numOBook;x++)
			{
			string title,isbn,auth,pub,add;
			int qty;
			double whole,retail;
			getline(data,title,',');
			getline(data,isbn,',');
			getline(data,auth,',');
			getline(data,pub,',');
			getline(data,add,',');
			data>>qty>>whole>>retail;

			book.setTitle(title);
			book.setIsbn(isbn);
			book.setAuthor(auth);
			book.setPub(pub);
			book.setDateAdded(add);
			book.setQty(qty);
			book.setWholeSale(whole);
			book.setRetail(retail);
			book.isEmpty(true);
			vecBooks.push_back(book);
		
			}
		}
	}
	data.close();
return vecBooks;

	};

if this helps the file format is
1
2
title,isbn,author,publisher,add, 23 2.34 4.50
title1,isbn1,author1,publisher1,add1, 123 12.34 14.50


update!
this->"expression block type is valid (phead->nblockUse)" is the main error that pops up??
Last edited on
Line 6, numOBook--;. What's the purpose of that?

Also line 16, for(int x=0;x<numOBook;x++) looks clumsy because you don't use the x variable inside the block.
It could be changed to while (num0Book-- != 0).
Thanks for replying

Line 8 is there because I read the file in another function to see how many entries there are. During the read i get an extra line so that compensates for the counter discrepancy.

as for line 16 i didn't think of that Thanks!
Topic archived. No new replies allowed.