Error happen when open file while migrate VC++ 6 to VS2008
-
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!
-
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!
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.
-
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.
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!
-
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!
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.
-
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!
-
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!
-
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.
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?
-
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?
-
I found some functions that pass std::istream or std::istrstream by value, not by reference, is that the reason to cause the problem?
-
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!
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.