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. Error happen when open file while migrate VC++ 6 to VS2008

Error happen when open file while migrate VC++ 6 to VS2008

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestionc++iosannouncement
10 Posts 4 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.
  • A Offline
    A Offline
    Andraw111
    wrote on last edited by
    #1

    Hi,dear all, I have a project created using C++ 6.0. Now I need to update it to VS2008, now I have a problem when I try to open a file. In C++ 6.0 #include ifstream INPFile(INPFileName, ios::nocreate); In VS2008 #include ifstream INPFile(INPFileName, ios::nocreate); the second line get the following error: Error 23 error C2039: 'nocreate' : is not a member of 'std::basic_ios<_Elem,_Traits>' Error 24 error C2065: 'nocreate' : undeclared identifier If I change the second line to the following: ifstream INPFile(INPFileName) then get new error as following error 2248: 'std::basic_ios<_Elem,_Traits>::basic_ios' : cannot access private member declared in class 'std::basic_ios<_Elem,_Traits>' How can I solve this issue? Thanks!

    A J 2 Replies Last reply
    0
    • A Andraw111

      Hi,dear all, I have a project created using C++ 6.0. Now I need to update it to VS2008, now I have a problem when I try to open a file. In C++ 6.0 #include ifstream INPFile(INPFileName, ios::nocreate); In VS2008 #include ifstream INPFile(INPFileName, ios::nocreate); the second line get the following error: Error 23 error C2039: 'nocreate' : is not a member of 'std::basic_ios<_Elem,_Traits>' Error 24 error C2065: 'nocreate' : undeclared identifier If I change the second line to the following: ifstream INPFile(INPFileName) then get new error as following error 2248: 'std::basic_ios<_Elem,_Traits>::basic_ios' : cannot access private member declared in class 'std::basic_ios<_Elem,_Traits>' How can I solve this issue? Thanks!

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

      This talks about the reason for the first error: http://www.devx.com/tips/Tip/14544[^] After your change however, the error about the private member doesn't make sense, you probably need to show a bit more of your code.

      A 2 Replies Last reply
      0
      • A Albert Holguin

        This talks about the reason for the first error: http://www.devx.com/tips/Tip/14544[^] After your change however, the error about the private member doesn't make sense, you probably need to show a bit more of your code.

        A Offline
        A Offline
        Andraw111
        wrote on last edited by
        #3

        Albert, thanks for your quick reply. My project has around 50 files, I already search all header files to check if any function pass fstream as argument, and modify them all to be passed as reference instead of as object. I don't understand why if I use following code: ifstream fin(OutputF, ios::in,ios::nocreate); I got error like "C2039: 'nocreate' : is not...", but if I modify it to: ifstream fin(OutputF, ios::in,ios::_Nocreate); I got other kind of error messge: "error C2248: 'std::basic_ios<_Elem,_Traits>::basic_ios' : cannot access private.." Thanks!

        A L 2 Replies Last reply
        0
        • A Andraw111

          Albert, thanks for your quick reply. My project has around 50 files, I already search all header files to check if any function pass fstream as argument, and modify them all to be passed as reference instead of as object. I don't understand why if I use following code: ifstream fin(OutputF, ios::in,ios::nocreate); I got error like "C2039: 'nocreate' : is not...", but if I modify it to: ifstream fin(OutputF, ios::in,ios::_Nocreate); I got other kind of error messge: "error C2248: 'std::basic_ios<_Elem,_Traits>::basic_ios' : cannot access private.." Thanks!

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

          Wait, if you're doing an ifstream (input), why are you specifiying "no create" at all? That doesn't make sense, it's not going to get created if it can't find it. That's only even applicable at all if you're opening in read/write or write modes.

          1 Reply Last reply
          0
          • A Andraw111

            Albert, thanks for your quick reply. My project has around 50 files, I already search all header files to check if any function pass fstream as argument, and modify them all to be passed as reference instead of as object. I don't understand why if I use following code: ifstream fin(OutputF, ios::in,ios::nocreate); I got error like "C2039: 'nocreate' : is not...", but if I modify it to: ifstream fin(OutputF, ios::in,ios::_Nocreate); I got other kind of error messge: "error C2248: 'std::basic_ios<_Elem,_Traits>::basic_ios' : cannot access private.." Thanks!

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            I do not think the nocreate option exists anymore, and it should not be necessary on an input stream. You need to use the latest definitions as described here[^].

            One of these days I'm going to think of a really clever signature.

            A 1 Reply Last reply
            0
            • L Lost User

              I do not think the nocreate option exists anymore, and it should not be necessary on an input stream. You need to use the latest definitions as described here[^].

              One of these days I'm going to think of a really clever signature.

              A Offline
              A Offline
              Andraw111
              wrote on last edited by
              #6

              Thanks, Albert and Richard, Both of you are right, yes, there is no nocreate. I solve it by remove it, but the main reason I got the " cannot access private member ..." error is that I have some functions that pass ifstream object as value, they should be passed by reference. Thanks again!

              1 Reply Last reply
              0
              • A Albert Holguin

                This talks about the reason for the first error: http://www.devx.com/tips/Tip/14544[^] After your change however, the error about the private member doesn't make sense, you probably need to show a bit more of your code.

                A Offline
                A Offline
                Andraw111
                wrote on last edited by
                #7

                Hi, I solve my issue posted yesterday, but today has another problem related to it. When I migrate another small project from C++ to VS2008, I double check all the function delcaration to make sure fstream object is passed by reference or pointer, but when I compile program, I still got two error messages, they are same and the only two errors. C2248: 'std::basic_ios<_Elem,_Traits>::basic_ios' : cannot access private member declared in class 'std::basic_ios<_Elem,_Traits>' In this case how should I find where the error come from?

                A 1 Reply Last reply
                0
                • A Andraw111

                  Hi, I solve my issue posted yesterday, but today has another problem related to it. When I migrate another small project from C++ to VS2008, I double check all the function delcaration to make sure fstream object is passed by reference or pointer, but when I compile program, I still got two error messages, they are same and the only two errors. C2248: 'std::basic_ios<_Elem,_Traits>::basic_ios' : cannot access private member declared in class 'std::basic_ios<_Elem,_Traits>' In this case how should I find where the error come from?

                  A Offline
                  A Offline
                  Andraw111
                  wrote on last edited by
                  #8

                  I found some functions that pass std::istream or std::istrstream by value, not by reference, is that the reason to cause the problem?

                  A 1 Reply Last reply
                  0
                  • A Andraw111

                    I found some functions that pass std::istream or std::istrstream by value, not by reference, is that the reason to cause the problem?

                    A Offline
                    A Offline
                    Andraw111
                    wrote on last edited by
                    #9

                    Yes, they also need to be passed by reference, now can be compile now.

                    1 Reply Last reply
                    0
                    • A Andraw111

                      Hi,dear all, I have a project created using C++ 6.0. Now I need to update it to VS2008, now I have a problem when I try to open a file. In C++ 6.0 #include ifstream INPFile(INPFileName, ios::nocreate); In VS2008 #include ifstream INPFile(INPFileName, ios::nocreate); the second line get the following error: Error 23 error C2039: 'nocreate' : is not a member of 'std::basic_ios<_Elem,_Traits>' Error 24 error C2065: 'nocreate' : undeclared identifier If I change the second line to the following: ifstream INPFile(INPFileName) then get new error as following error 2248: 'std::basic_ios<_Elem,_Traits>::basic_ios' : cannot access private member declared in class 'std::basic_ios<_Elem,_Traits>' How can I solve this issue? Thanks!

                      J Offline
                      J Offline
                      jschell
                      wrote on last edited by
                      #10

                      I would suppose that passing the fstream by value in 6.0 was wrong too. It might have worked but only by luck. A fstream is a representation of a computer resource. Passing by value implicitly duplicates the representation without duplicating the actual resource. Thus it represents a broken design/implementation.

                      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