Like Tree15Likes

oparator new

This is a discussion on oparator new within the C++ Programming forums, part of the General Programming Boards category; Yes I'm using Win32 API CreateFile() because I need to write and read to the file in the same time ...

  1. #16
    Registered User
    Join Date
    Dec 2007
    Posts
    825
    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.
    Compiler MSVC++ 2013 with Code::Blocks.

  2. #17
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,313
    Quote Originally Posted by Ducky
    I need to write and read to the file in the same time
    What do you mean?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #18
    Registered User
    Join Date
    Dec 2007
    Posts
    825
    Sorry, I meant that I need to write to it and read from it from time to time. It's a log file.
    Compiler MSVC++ 2013 with Code::Blocks.

  4. #19
    Registered User
    Join Date
    Oct 2006
    Posts
    2,590
    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
    825
    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.
    Compiler MSVC++ 2013 with Code::Blocks.

  6. #21
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,033
    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
    Ducky likes this.
    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
    825
    Looks like it's working this time, dont know what I did wrong last time. Thanks anyway. ;-)
    Compiler MSVC++ 2013 with Code::Blocks.

  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
    825
    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
    Compiler MSVC++ 2013 with Code::Blocks.

  10. #25
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    4,415
    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
    Ducky likes this.

Page 2 of 2 FirstFirst 12
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, 10:24 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21