Нижегородский Форум Друзей

Нижегородский Форум Друзей (http://forum.nnov.org/)
-   Вопросы, Проблемы и Обсуждение (http://forum.nnov.org/obsuzhdaem-i-kachaem/soft/voprosy-problemy-i-obsuzhdenie/)
-   -   C++ & MFC (http://forum.nnov.org/obsuzhdaem-i-kachaem/soft/voprosy-problemy-i-obsuzhdenie/19549-c-mfc.html)

Kernel Panic 18.11.2007 11:56

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 в МСДНе и в нете нет! А перечитывать горы книг у меня нет времени...

Люди добрые, объясните пожалуйста, че нужно написать, чтобы компилятор снизошел до того чтобы скомпилить мою прогу?

NetMan 08.12.2007 19:26

Вот накатал исходник, читает из файла не более 20 первых символов =)
Код:

        CFile file;
        LPTSTR fileName="C:\\testing.txt";
        char buf[20];

        file.Open(fileName, CFile::modeRead);
        UINT bytesRead = file.Read(buf, sizeof(buf)-1);
        buf[bytesRead]='\0';
        file.Close();

        AfxMessageBox(buf);


Kernel Panic 08.12.2007 19:44

на строчке LPTSTR fileName="C:\\testing.txt";
ошибка
Error 1 error C2440: 'initializing' : cannot convert from 'const char [12]' to 'LPTSTR'

NetMan 11.12.2007 22:12

У меня нормально компилится на MS Visual Studio 6.0....


Часовой пояс GMT +3, время: 15:30.

Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd. Перевод:
Search Engine Friendly URLs by vBSEO 3.6.0zCarot
© 2005—2015 ООО «Интернет компания ННОВ.РУ», friends.nnov.ru
Реклама на форуме