Thread: oparator new

  1. #16
    Registered User
    Join Date
    Dec 2007
    Posts
    932
    Yes I'm using Win32 API CreateFile() because I need to write and read to the file in the same time and
    I tried a lot of times but I cannot do it with fstream.
    I dont want to close and reopen the file all the time I want to leave it open.
    Using Windows 10 with Code Blocks and MingW.

  2. #17
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Ducky
    I need to write and read to the file in the same time
    What do you mean?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #18
    Registered User
    Join Date
    Dec 2007
    Posts
    932
    Sorry, I meant that I need to write to it and read from it from time to time. It's a log file.
    Using Windows 10 with Code Blocks and MingW.

  4. #19
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    perhaps you're confused about how log files are supposed to work. generally a log file is an output-only proposition. a program rarely reads back in its own log file.

  5. #20
    Registered User
    Join Date
    Dec 2007
    Posts
    932
    In my case I need to do both. But what matters right now is that I couldn't do it with fstream.
    I found a sample code that worked in itself but when I tried to implement it in my code it wasn't working.
    But doesn't matter, no big deal.
    Using Windows 10 with Code Blocks and MingW.

  6. #21
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by Ducky View Post
    Yes I'm using Win32 API CreateFile() because I need to write and read to the file in the same time and
    I tried a lot of times but I cannot do it with fstream.
    But you can:
    fstream::fstream - C++ Reference
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #22
    Registered User
    Join Date
    Dec 2007
    Posts
    932
    Looks like it's working this time, dont know what I did wrong last time. Thanks anyway. ;-)
    Using Windows 10 with Code Blocks and MingW.

  8. #23
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    Quote Originally Posted by iMalc View Post
    Interesting enough going from C to C++ would actually solve the issue by using std::string, though fundamentally I agree with the argument that coming from a high level language can be harder to understand low level optimization.

    It always struck me as odd the null terminating string concept in C. I think the LV (length- value) notion would just have been better. So first bytes have the total length of the string and then you (the parser) knows how much you need to read. Same memory footprint for strings less than 255 bytes as well. A struct is even better of course.

  9. #24
    Registered User
    Join Date
    Dec 2007
    Posts
    932
    To Elysia and Laserlight, unfortunately you cannot open a file in read & write mode, keep it open and tell the size of the file in C++.

    Now I remember the reason why I didn't use fstream.

    tellg() returning -1
    Using Windows 10 with Code Blocks and MingW.

  10. #25
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    To Elysia and Laserlight, unfortunately you cannot open a file in read & write mode, keep it open and tell the size of the file in C++.
    If you don't know how to use a tool, that is a problem with your lack of knowledge.

    Now I remember the reason why I didn't use fstream.
    No. You didn't. You didn't have a reason for not using `fstream'.

    You've found an area where you lack knowledge and are now trying to justify an preconceived notion.

    Soma

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Confused by '&' oparator
    By Ducky in forum Windows Programming
    Replies: 3
    Last Post: 08-20-2008, 09:24 AM