fffffff
Тема: C++ & MFC
Показать сообщение отдельно
Старый 18.11.2007, 11:56   #1
Заслуженные
 
Аватар для Kernel Panic
 
Регистрация: 01.04.2008
Пол: M
Сообщений: 1,297
Поблагодарил: 86
Поблагодарили 1,194 раз в 715 сообщениях
Открыли хайд :
0 в этом сообщении
47 Всего


По умолчанию C++ & MFC

Кто-нибудь объясните мне пожалуйста, как использовать долбаный класс CFile... Добрый дядя Билл с его тимом пишут вот такое вот описание метода open:

вот так вот...:
Код:
virtual BOOL Open(
   LPCTSTR lpszFileName,
   UINT nOpenFlags,
   CFileException* pError = NULL 
);

Parameters
lpszFileName
A string that is the path to the desired file. The path can be relative, absolute, or a network name (UNC).

nOpenFlags
A UINT that defines the file's sharing and access mode. It specifies the action to take when opening the file. You can combine options by using the bitwise-OR ( | ) operator. One access permission and one share option are required; the modeCreate and modeNoInherit modes are optional. See the CFile constructor for a list of mode options.

pError
A pointer to an existing file-exception object that will receive the status of a failed operation.


Я пешу:

Код:
1: char buf[10];
2: char* ppath = "c:\test.txt";
3: CFile myfile;
4: CFileException fe;
5: myfile.Open( ppath, CFile::modeReadWrite, &fe );
6: myfile.Read( &buf, 10 );
7: for( int i = 1; i <= 10; i++ )
8:       std::cout << buf[i];
на строчке 4 цука кампилятор выдает:
Цитата:
Error 1 error C2664: 'CFile::Open' : cannot convert parameter 1 from 'char *' to 'LPCTSTR'
если в этой строчке заменяю ppath конкретно на "c:\test.txt", то тогда он выдает
Цитата:
Error 1 error C2664: 'CFile::Open' : cannot convert parameter 1 from 'const char [11]' to 'LPCTSTR'
МЛИН! тут почти по-русски написано:
lpszFileName:
A string that is the path to the desired file. The path can be relative, absolute, or a network name (UNC).
Я и пешу стринг! с какого хрена мелкософтерскому компилятору чето не нравиццо? Я уже по-вяскому попробовал: и описать const char* ppath = "c:\test.txt", и просто char*... Нифига не компилит! А больше всего меня раздражает что во все примеры в нете выглядят примерно так:
Цитата:
char* pszFileName = "c:\\test\\myfile.dat";
CFile myFile;
CFileException fileException;

if ( !myFile.Open( pszFileName, CFile::modeCreate |
CFile::modeReadWrite, &fileException ) )
Никакой полезной (для данного вопроса) инфы по типу LPCSTR в МСДНе и в нете нет! А перечитывать горы книг у меня нет времени...

Люди добрые, объясните пожалуйста, че нужно написать, чтобы компилятор снизошел до того чтобы скомпилить мою прогу?
__________________
[Для просмотра данной ссылки нужно зарегистрироваться]
Kernel Panic вне форума  
Ответить с цитированием