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.

Michael Murdock
  • 129
  • 1
  • 9

2 Answers2

1

As others have pointed out your issue is caused by the escape character \.

"c:\data\test.txt"

Should be

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

You can find out more about escape sequences here.

To avoid confusion you could use / instead of \ in your file paths.

"C:/data/test.txt"
Freddy
  • 2,249
  • 1
  • 22
  • 31
  • My bad on this post. I'm actually using "\\" for backslash in the code as I already said above. – Michael Murdock Feb 20 '15 at 17:49
  • Please, do not recommend using forward slashes in Windows path names. As soon as you prepend "\\?\" to the path name (to relax the `MAX_PATH` limitation), forward slashes no longer get translated to directory separators. – IInspectable Feb 21 '15 at 01:14
0

To those who are still following this, after two and a half days, I did get to the bottom of what was going on. Sorry for the delay in posting this. Actually, I had completely forgot about it.

This was a case of access permission on a parent directory. Not just regular denial. I mean special denial of opening a file to add to it (open with append). You can't even normally see these settings unless you go to advanced mode on the security tab of a file or directories property window. Even then you have to go a couple extra steps. So the directory above the directory my file was in had this setting set (for some unbelievable reason). Anyway, I verified all three methods work now (fopen(), CFile.open(), stream.open()).

Thanks for all the ideas, I learned a lot I didn't know before. Some of the ideas were great.

Maddog

Michael Murdock
  • 129
  • 1
  • 9