Thanks all. Problem solved. ( You guys are good :D)
Type: Posts; User: johnnyd
Thanks all. Problem solved. ( You guys are good :D)
I'm glad you posted PJYelton, because from your code:
vector<myclass> vec1;
would give me the compile error I mentioned earlier. Whereas, in your case, where MS VC++6 you said, it...
No, what I meant was, do most people build their classes with the assignment operator overloaded and have a copy constructor? The reason I ask is because the text (and most other sources) do not...
You see, it's things like that which annoy me. :mad: They [the text] tell you how to do everything except the most important thing. Now how was I supposed to know that vectors for user defined...
Yes, a vector of objects. You know it's interesting, that's exactly how I defined my vector of objects. Check this:
vector<Book> vBook;
Which is supposed to be a vector of books. However,...
I agree, it should. It's just that it doesn't work when I use my own custom defined types. I was wondering if there was something else that I needed to do. Hence, the post. Any ideas?
Hey folks. Question: How do you implement Vectors for a user defined class? Is this even possible? I've searched the boards, the faq and the tutorials and all of them only refer to using the...
Polymorphic... how far away from the Microsoft Bldg are you situated?
STRESS!!
Can you imagine? I actually went back to my bashy gui ridden C project from last year that Prelude helped me out with and I actually checked out the files that were written to the hard...
I finally realised what I was doing wrong why fstream wasn't working for me. It was because everytime I read the record, the file pointer moves to the beginning of the next record. Therefore, I have...
Got it. It's a shame though that C's implementation of files was so much simpler and more reliable. I get the feeling that somehow they were trying to reinvent the wheel with the text mode and it...
That's interesting Swoopy, I've never thought of that one. I'll give it a shot.
I just tested it and it works. All the time.
I've come to realise why binary mode wasn't working for me. It was because I used fstream to create the file handler, and not ofstream. ofstream works...
Gotcha.
Starting afresh... (I wish they told us these things in school and in books)
When you say text, do you mean that all of the variables in the class should be of the char* type? or do you mean text as in a literal string like "The quick brown fox was nuked by the lazy dog"?
I've actually tried that. It doesn't work. And exactly as how you typed it too!
No it's not being opened in binary. It's in text mode. Here's how I play with it:
obook.open("books.dat", ios::ate);
if (obook){
newBook = Book(isbn, author, title, publisher, pPlace,...
Check out the following code:
obook.write(reinterpret_cast< const char * >(&newBook), sizeof(Book));
...where obook is an ofstream variable that opens a file using ios::ate and newBook is...
I'm just realising that. Thanks for the keen eye. ;)
Alas, I believe you have hit the nail on the head. I didn't know it made a difference. Thanks again Codeplug.
It would seem as if I have to totally abandon the Deitel and Deitel 4th ed. It is...
This works fine:
Book test; //Book is my custom class
ifstream inbook("book.dat", ios::in);
ofstream outbook "book.dat", ios::ate);
inbook.read(reinterpret_cast< char* >(&test),...
Hi all...
I have not seen a faq or post that matches my problem. Hopefully, you folks can lend me your expertise once again.
I'm using random files to store some data. When I use ofstream to...
Thanks Codeplug - works beautifully. I just wished you had been a little clearer in the first post regarding the Deitel and Deitel. Essentially you had already answered my question.
But I think...
Umm... Codeplug... I'd hate to break this to ya... but that doesn't seem to work either.
Can you declare a variable to do BOTH reading (read) and writing? (write)
That's what I am trying to do....
Thanks Codeplug - I think it's more of my misreading your post. Sorry...
It's still a lot more work than C though. :D