0

Using Visual Studio 2012 & with Project properties:

  1. Configuration Properties: General: Project Defaults:Character Set: Not Set
  2. Configuration Properties: C++: Language:Treat WChar_t as Built In Type: No

I use an ofstream with following snippet of code: Note: the path "C:\data" is valid for this example

ofstream fexp;
fexp.open("c:\data\test.txt", ios::out|ios::binary|ios::app);
fexp << "writing some text to file with append in binary" << endl;
fexp.flush();
fexp.close();

If the file was not present in the directory, the file would be open, text written, etc. If the file already existed the file is not opened, not written to, etc. No exception occurred and no error code was found (in errno). While debugging internal to open() method, I found some internal open calls were trying to copy the filename string into wchar_t type and exited with an internal error of 13 (looking up MS Constants = Open Aborted).

MBCS has been deprecated so I don't want to be set to that. Only other option is Unicode which breaks half of my changes. Why can't I make use of the std io library??!!!

What is weirder still I had some of this working with second switch to no with 1st set to MBCS. The code worked though a lot of places in dealing with GUI contaniners such as CEdit, I had a lot superfluous code to convert from CString to string if I had to. If in essence the representation of CString is a const char* which is somewhat close to LPCTSTR (not quite). It "SHOULD" be somewhat "SIMPLE" to convert from CString to string. It is not because UNECESSARY complications of switches between UTF-8 and UTF-16 that I am not engaged in. I desire my char to be STRICTLY 1-BYTE.

What is the closest path through this madness? Do I go back to back to MBCS (even though deprecated) and change all the container methods from GetWindowText() to GetWindowTextA() for example or abandon the use of streams in Visual Studio, or what???

Please Advise, if you can... Any help would be appreciated. Thanks.

Maddog

ps: Please don't go to the trouble to convert me to embrace the full Wide environment in my code, when my product will not be sold in Asia or Arabia.

pps: one final note, I got into this because, I noted my initial install of Visual Studio 2012 defaulted to MBCS.

4

2 回答 2

1

正如其他人指出的那样,您的问题是由转义字符引起的\

"c:\data\test.txt"

应该

"c:\\data\\test.txt"

您可以在此处找到有关转义序列的更多信息。

为避免混淆,您可以在文件路径中使用/而不是。\

"C:/data/test.txt"
于 2015-02-20T16:46:39.717 回答
0

对于那些仍在关注这一点的人,在两天半之后,我确实了解了到底发生了什么。很抱歉延迟发布此内容。其实,我已经完全忘记了。

这是对父目录的访问权限的情况。不只是经常否认。我的意思是特别拒绝打开要添加的文件(使用附加打开)。除非您在文件或目录属性窗口的安全选项卡上进入高级模式,否则您甚至无法正常看到这些设置。即使那样,您也必须采取一些额外的步骤。因此,我的文件所在目录上方的目录设置了此设置(出于某种令人难以置信的原因)。无论如何,我验证了所有三种方法现在都有效(fopen(),,,CFile.open()stream.open()

感谢所有的想法,我学到了很多我以前不知道的东西。有些想法很棒。

疯狗

于 2015-03-06T21:54:08.660 回答