::ifstream.open behaves differently in VC6 and VS2010
-
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?
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] -
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] -
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); -
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); -
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.
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...
-
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...