hi all,
i need to set a directory path into a Cstring variable, as follows:
CString directory;
directory ="\\D:\data\data";
but error code occur said that d: is unrecognised character escape sequence, how do i cope with that?
thanks!
hi all,
i need to set a directory path into a Cstring variable, as follows:
CString directory;
directory ="\\D:\data\data";
but error code occur said that d: is unrecognised character escape sequence, how do i cope with that?
thanks!
Can you post the actual error message, it will help us help you easier.
Joe
A quality job is not necessarily a *good* job. A quality job is, by definition, conformance to requirements. Therefore a *good* job, may not be a quality job.
warning C4129: 'd' : unrecognized character escape
since i need to use the creatfile function to read file in that directory, so i need to set path of that directory.
Last edited by mr_empty; 11-18-2007 at 09:02 PM.
Code:directory ="\\D:\\data\\data";
Code:i use these coding: dest= "\\D:\\data\\data\\file14.txt"; HANDLE hFile = CreateFile (dest, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_ALWAYS, 0,NULL); if (hFile == INVALID_HANDLE_VALUE){// if setting/file not valid DWORD dw = GetLastError (); debug = "Step 1"; detail.DetailValue = debug; } detail.DoModal(); the above command display "step 1" i still can't access the file, do u know why? thanks very much!!
now i use this:
i still can't access the file, it displays the step 12, anyone know why? thanks a lot!!Code:HANDLE hFile = CreateFile(L"D:\\file.txt", GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); CString debug; if (INVALID_HANDLE_VALUE == hFile){// if setting/file not valid debug = "Step 12"; detail.DetailValue = debug; } detail.DoModal();
Any reason you're using CreateFile instead of std::istream?
coz i need to display the content in the dialog editbox
can istream do this?
Yes, and it's much simpler too. Not to mention pretty much the C++ standard.
> anyone know why?
Well you could call GetLastError() to find out more information (like you did before).
There's even an API to turn that error status into a string.
Why did you use L"D:\\file.txt" and not TEXT("D:\\file.txt")
The latter does the right thing whether you're compiling in ASCII mode or UNICODE mode.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
but how to display the getlasterror code?
by the way i use the TEXT() function but no difference
Why do you start the string with a backslash in the first place? A Windows path is "D:\...", not "\D:\...".
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
coz ("D:\\") or ("\D:\\")makes no different in result and ("\D:\\") will get warnning
I'm not talking about escaped strings. I'm simply talking about Windows paths, outside the programming domain.
But I see that in the later snippets, you dropped that initial backslash anyway.
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
i have got the eror message from the getlasterror:
the data area passed to a system call is too small
but i dun understand, how can i fix it? thaknks!!