Re: [boost] [filesystem] wfstream file open does not create file in std::ios_base::out mode

Hi, I upgraded to boost version 1.43, but that did not help. Still file creation fails with wfstream and error code set is ERROR_FILE_NOT_FOUND. Below code captures the error codes #include "boost/filesystem/fstream.hpp" int main() { boost::filesystem::path pA("C:\\testA.txt"); boost::filesystem::wpath pW(L"C:\\testW.txt"); boost::filesystem::fstream fileHandleA; boost::filesystem::wfstream fileHandleW; fileHandleA.open(pA, std::ios_base::out); cout << "fileHandleA.fail() return value is: " << fileHandleA.fail() << endl; cout << "Error code is: " << GetLastError() << endl; fileHandleW.open(pW, std::ios_base::out); cout << "fileHandleW.fail() return value is: " << fileHandleW.fail() << endl; cout << "Error code is: " << GetLastError() << endl; return 0; } Am I doing something wrong? Regards, Kiran On 2010-06-19 00:44, Beman Dawes wrote:
On Thu, Jun 17, 2010 at 9:48 AM, Ramakrishna, Kirankumar IN BLR SISL <Kiran.Ramakrishna@???> wrote:
Hello,
I am using boost version 1.42 and the below code is tested on Windows Xp SP3 and Suse 11.2
The below code creates new file when opened using fstream object, but fails to create when opened using wftream object. This behavior is consistent across platforms (Windows and Linux). Also the error code which I get after fileHandleW.open call is,
 1.  ERROR_FILE_NOT_FOUND for  std::ios_base::out  2.  ERROR_NEGATIVE_SEEK for std::ios_base::app
In case of append mode, the file gets created. But still I get the above mentioned error code.
Important notice: This e-mail and any attachment there to contains corporate proprietary information. If you have received it by mistake, please notify us immediately by reply e-mail and delete this e-mail and its attachments from your system. Thank You.

On Wed, Jun 23, 2010 at 4:27 AM, Ramakrishna, Kirankumar IN BLR SISL <Kiran.Ramakrishna@siemens.com> wrote:
Hi,
Please don't top post. Top-posting is not acceptable. See http://www.boost.org/community/policy.html#quoting --Beman (Moderator)

On Wed, Jun 23, 2010 at 4:27 AM, Ramakrishna, Kirankumar IN BLR SISL <Kiran.Ramakrishna@siemens.com> wrote:
Hi,
I upgraded to boost version 1.43, but that did not help. Still file creation fails with wfstream and error code set is ERROR_FILE_NOT_FOUND. Below code captures the error codes
#include "boost/filesystem/fstream.hpp" int main() { boost::filesystem::path pA("C:\\testA.txt"); boost::filesystem::wpath pW(L"C:\\testW.txt"); boost::filesystem::fstream fileHandleA; boost::filesystem::wfstream fileHandleW; fileHandleA.open(pA, std::ios_base::out); cout << "fileHandleA.fail() return value is: " << fileHandleA.fail() << endl; cout << "Error code is: " << GetLastError() << endl; fileHandleW.open(pW, std::ios_base::out); cout << "fileHandleW.fail() return value is: " << fileHandleW.fail() << endl; cout << "Error code is: " << GetLastError() << endl; return 0; }
Am I doing something wrong?
Please, this isn't the right place to post "How do I program in C++?" level questions. The above program won't compile. Beyond the obvious errors, it uses poor practices like writing test files to the root directory. And, once the errors are corrected, it does run OK, at least on the trunk. Sorry, but you have exhausted my patience so I didn't try it on the actual 1.43 release. --Beman

On Wed, Jun 23, 2010 at 7:20 AM, Beman Dawes <bdawes@acm.org> wrote:
On Wed, Jun 23, 2010 at 4:27 AM, Ramakrishna, Kirankumar IN BLR SISL <Kiran.Ramakrishna@siemens.com> wrote:
Hi,
I upgraded to boost version 1.43, but that did not help. Still file creation fails with wfstream and error code set is ERROR_FILE_NOT_FOUND. Below code captures the error codes
#include "boost/filesystem/fstream.hpp" int main() { boost::filesystem::path pA("C:\\testA.txt"); boost::filesystem::wpath pW(L"C:\\testW.txt"); boost::filesystem::fstream fileHandleA; boost::filesystem::wfstream fileHandleW; fileHandleA.open(pA, std::ios_base::out); cout << "fileHandleA.fail() return value is: " << fileHandleA.fail() << endl; cout << "Error code is: " << GetLastError() << endl; fileHandleW.open(pW, std::ios_base::out); cout << "fileHandleW.fail() return value is: " << fileHandleW.fail() << endl; cout << "Error code is: " << GetLastError() << endl; return 0; }
Am I doing something wrong?
Please, this isn't the right place to post "How do I program in C++?" level questions.
The above program won't compile. Beyond the obvious errors, it uses poor practices like writing test files to the root directory.
And, once the errors are corrected, it does run OK, at least on the trunk. Sorry, but you have exhausted my patience so I didn't try it on the actual 1.43 release.
That was a pretty grouchy answer, so let me try again with a bit more politeness. Your test program above is overly complex, missing several #includes, and tries to mix standard library and Win32 error handling, which don't mix. Here is a simpler test program that will actually compile: #include "boost/filesystem/fstream.hpp" #include <iostream> int main() { boost::filesystem::ofstream file_a("file_a.txt"); std::cout << "file_a creation " << (file_a ? "OK" : "failed") << '\n'; boost::filesystem::wofstream file_w(L"file_w.txt"); std::cout << "file_w creation " << (file_w ? "OK" : "failed") << '\n'; return 0; } I compiled it against 1.43.0 with VC++ 8 Express like this:
cl /EHsc /I d:\boost_1_43_0 test.cpp /link /LIBPATH:D:\boost_1_43_0\stage\lib Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.30729.01 for 80x86 Copyright (C) Microsoft Corporation. All rights reserved.
test.cpp Microsoft (R) Incremental Linker Version 9.00.30729.01 Copyright (C) Microsoft Corporation. All rights reserved. /out:test.exe /LIBPATH:D:\boost_1_43_0\stage\lib test.obj And ran it like this:
test file_a creation OK file_w creation OK dir Volume in drive C has no label. Volume Serial Number is D4A2-EC0D
Directory of C:\temp 06/23/2010 01:54 PM <DIR> . 06/23/2010 01:54 PM <DIR> .. 06/23/2010 01:54 PM 0 file_a.txt 06/23/2010 01:54 PM 0 file_w.txt 06/23/2010 01:54 PM 360 test.cpp 06/23/2010 01:54 PM 151,040 test.exe 06/23/2010 01:54 PM 274,261 test.obj ... You might start by trying to compile and run that program yourself. Once you get it running, then you might try to make a series of very small changes, compiling and testing at each step of the way, and building up to larger and more complex programs. HTH, --Beman
participants (2)
-
Beman Dawes
-
Ramakrishna, Kirankumar IN BLR SISL