Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. ::ifstream.open behaves differently in VC6 and VS2010

::ifstream.open behaves differently in VC6 and VS2010

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    KASR1
    wrote on last edited by
    #1

    In VC6 when we use ::ifstream.open("test.txt") call creates a file if the specified file is not found in the location. But in VS2010 it does not create a file when its not found. Why is this differece and how to resolve this problem?

    CPalliniC 1 Reply Last reply
    0
    • K KASR1

      In VC6 when we use ::ifstream.open("test.txt") call creates a file if the specified file is not found in the location. But in VS2010 it does not create a file when its not found. Why is this differece and how to resolve this problem?

      CPalliniC Offline
      CPalliniC Offline
      CPallini
      wrote on last edited by
      #2

      It looks VS2010 is more 'compliant' (see ifstream::open[^]). It doesn't look a problem to me, however you may provide the second argument with the open mode you wish, if you need.

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
      [My articles]

      In testa che avete, signor di Ceprano?

      K 1 Reply Last reply
      0
      • CPalliniC CPallini

        It looks VS2010 is more 'compliant' (see ifstream::open[^]). It doesn't look a problem to me, however you may provide the second argument with the open mode you wish, if you need.

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
        [My articles]

        K Offline
        K Offline
        KASR1
        wrote on last edited by
        #3

        i m wonderring which second argument option will work like as vc6.

        A 1 Reply Last reply
        0
        • K KASR1

          i m wonderring which second argument option will work like as vc6.

          A Offline
          A Offline
          Albert Holguin
          wrote on last edited by
          #4

          Try them out to see which one works as desired... do you really need people to do all the thinking for you? if the default is ios_base::in (see parameters):

          void open ( const char * filename, ios_base :openmode mode = ios_base::in );

          then just try making it ios_base::out (if you're only writing to it, or in/out if you're reading and writing).

          open(filename, ios_base::out);
          //Or maybe
          open(filename, ios_base::in | ios_base::out);

          K 1 Reply Last reply
          0
          • A Albert Holguin

            Try them out to see which one works as desired... do you really need people to do all the thinking for you? if the default is ios_base::in (see parameters):

            void open ( const char * filename, ios_base :openmode mode = ios_base::in );

            then just try making it ios_base::out (if you're only writing to it, or in/out if you're reading and writing).

            open(filename, ios_base::out);
            //Or maybe
            open(filename, ios_base::in | ios_base::out);

            K Offline
            K Offline
            KASR1
            wrote on last edited by
            #5

            Even i tried all this and posted here when things are not working. None of the above options creates a file when its not found. only VC6 open does.

            A 1 Reply Last reply
            0
            • K KASR1

              Even i tried all this and posted here when things are not working. None of the above options creates a file when its not found. only VC6 open does.

              A Offline
              A Offline
              Albert Holguin
              wrote on last edited by
              #6

              if you're using the ifstream version, it sort of implies that you're pulling in data (thus, why would you want to create a file if it doesn't exist)... did you try to fstream/ofstream version of open? did you try putting in the whole path to the file to see if that made a difference? Basic debugging... come on...

              K 1 Reply Last reply
              0
              • A Albert Holguin

                if you're using the ifstream version, it sort of implies that you're pulling in data (thus, why would you want to create a file if it doesn't exist)... did you try to fstream/ofstream version of open? did you try putting in the whole path to the file to see if that made a difference? Basic debugging... come on...

                K Offline
                K Offline
                KASR1
                wrote on last edited by
                #7

                finally i confirmed that vc6 ifstream::open has bug and this has been fixed in vs2010. So i modified the code to match with existing behaviour.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups