fstream doesn't work well

This is a discussion on fstream doesn't work well within the C++ Programming forums, part of the General Programming Boards category; C++ was developed from C. For the most part of the language, C++ uses C as a subset. The base ...

  1. #16
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,383
    C++ was developed from C.
    For the most part of the language, C++ uses C as a subset.
    The base of C++ programming language is this C subset.

    These are more or less the three more recurrent phrases you can read on most books dealing with C++, Siav. C++ plan is to be a better C not by being itself an entirely different language, but by building on its predecessor.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  2. #17
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,231
    There is no need for STL to call a C function. It can has its own in C++. C++ is a better C but is not its wrapper, is it?
    If people say C++ is completely satisfactory, I ask why not using only C++. Whole new STLs without using any C header. Of course anybody can still use C headers when needed.
    Last edited by siavoshkc; 08-16-2006 at 05:03 PM.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  3. #18
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    I don't think you are understanding the concept of C++ as a language. Why would you re-write code that does exactly what you want, has been thoroughly tested, and already works? You do realize that some C and C++ standard functions are implemented with assembly, right? Why not just implement them in C or C++ instead?

    One of the reasons C++ is "completely satisfactory" is that it includes almost all of C and so it has a huge codebase that it can use.

    In addition, a standard library is different than the language itself. A library is just a library, so it has to be implemented somehow. What type of code the implementation uses is immaterial if it gets the job done well.

  4. #19
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,383
    When you call a C function within a C++ base, you are still compiling with C++. So, you can actually say that you are calling a function that is syntactically equivalent to its C counterpart. You are not calling a C function. But a C++ one that may or may not be implemented differently that it is in its C incarnation. i.e.The compiler may or may not reinvent the wheel. It's up to the implementators.

    It was very important for the creation process of the C++ programming language to make it as compatible as possible with C. As such, it is not only the STL that uses C functions. You, the coder do to. All the time. As Daved said, why develop a programming language that one wants to be compatible with C, but then implement every little detail as if the tried and tested C implementation was worth nothing?
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  5. #20
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,231
    I know exactly what you are saying guys.
    Thanks for all of answers.
    I will think more about it.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  6. #21
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,586
    On a side note there are times when big daddy XP won't let you open files in certain access modes. In other words there exist perfectly valid combinations of flags that Windows XP will puke at.

  7. #22
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    Quote Originally Posted by Bubba
    On a side note there are times when big daddy XP won't let you open files in certain access modes. In other words there exist perfectly valid combinations of flags that Windows XP will puke at.
    are you talking about attempting to open a read-only file for writing? I think most operating systems will not allow that. and of course the user must have read/write permission in the directory that contains the desired file on NTFS file system. That too is common with *nix. Otherwise, maybe you would like to explain.

  8. #23
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,231
    Problem remains. I tried open it for output and closing it. But each time it clears file containments. (like trunc).

    [edit]
    So I used ios_base::ape and it worked.

    [edit2]
    I mean ios_base::app, sorry.
    Last edited by siavoshkc; 08-17-2006 at 01:24 PM.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  9. #24
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    use ios::app.

  10. #25
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,586
    are you talking about attempting to open a read-only file for writing? I think most operating systems will not allow that. and of course the user must have read/write permission in the directory that contains the desired file on NTFS file system. That too is common with *nix. Otherwise, maybe you would like to explain.
    Yes, read only is one of them. Also XP doesn't seem to like read/write access specified. If you don't specify it, it will work just fine. Most of my problems come from files in binary mode.
    _open suffers from this a lot. I'm sure fstream also has perfectly valid 'C' combinations of flags that Windows just simply won't allow.

    I've also had XP deny me access to save a file in any other directory except my own. This was in MFC while using _open. I fixed it by switching to CArchive and CFile.

  11. #26
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,231
    Is this standard to for this function to clear file contents each time?
    Code:
    fstream f;
    f.open("Name.mmm", ios_base::out);  //<<THIS<<
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  12. #27
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    Yes. If you don't specify anything, ios_base::trunc is assumed.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why don't the tutorials on this site work on my computer?
    By jsrig88 in forum C++ Programming
    Replies: 3
    Last Post: 05-15-2006, 10:39 PM
  2. Problems in getting OpenGL to work
    By zonf in forum C Programming
    Replies: 5
    Last Post: 02-13-2006, 03:48 AM
  3. Why won't my OpenGL work?
    By Raigne in forum C++ Programming
    Replies: 7
    Last Post: 11-26-2005, 10:53 AM
  4. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 11:39 AM
  5. DLL __cdecl doesnt seem to work?
    By Xei in forum C++ Programming
    Replies: 6
    Last Post: 08-21-2002, 04:36 PM

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