CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 27

Thread: CFile

  1. #1
    Join Date
    Jun 2004
    Location
    bucharest, ro
    Posts
    53

    CFile

    hello,


    I need to make a console application that uses the CFile class. I understood that this class is from MFC.

    When I create a new MFC application it includes lots of headers and tons of .cpp files with lots of code inside... and all I need is a console application that onlyuses that CFile class.

    What is the minimum number of headers I must include in the .cpp file in order to be able to use CFile in my empty console application? I do not want to start MFC application because I seem to get lost in all the .cpp and .h that Visual Studio creates automatically...

    Thank you and if my question was not clear I will rephrase.
    the doer alone learneth. (nietzsche)

  2. #2
    Join Date
    Sep 2001
    Location
    Bilbao (spain)
    Posts
    110

    Re: CFile

    Quote Originally Posted by s|lent
    hello,


    I need to make a console application that uses the CFile class. I understood that this class is from MFC.

    When I create a new MFC application it includes lots of headers and tons of .cpp files with lots of code inside... and all I need is a console application that onlyuses that CFile class.

    What is the minimum number of headers I must include in the .cpp file in order to be able to use CFile in my empty console application? I do not want to start MFC application because I seem to get lost in all the .cpp and .h that Visual Studio creates automatically...

    Thank you and if my question was not clear I will rephrase.
    I think is a question more appropiate for other forum. This is for non visual c++ issues, and MFC are part of Visual C++.

  3. #3
    Join Date
    May 2006
    Location
    Norway
    Posts
    1,709

  4. #4
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: CFile

    [ redirected ]
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  5. #5
    Join Date
    Jun 2004
    Location
    bucharest, ro
    Posts
    53

    Re: CFile

    Quote Originally Posted by laitinen
    set the runtime library to multi threaded (MT) ...
    Sorry for being so narrow, but how exactly do I do that?

    I have looked in the Project's Properties but could not find such thing.
    the doer alone learneth. (nietzsche)

  6. #6
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: CFile

    In VC6 it's under the C/C++ tab, Code Generation category.

  7. #7
    Join Date
    Jun 2004
    Location
    bucharest, ro
    Posts
    53

    Re: CFile

    Thank you for the above. I have somehow made it accept to

    #include <afx.h> by using the "use MFC in a shared .dll" property.

    However Ive only written a few lines and they do not seem to work:

    Code:
    #include <afx.h>
    using namespace std;
    
    void main()
    {
    CFile fisier;
    fisier.Open("c:\\test2.txt", CFile::modeCreate|CFile::modeWrite);
    
    
    }
    the error I have been given is:

    error C2664: 'CFile::Open' : cannot convert parameter 1 from 'const char [13]' to 'LPCTSTR'
    Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast


    Please, what is it that I am doing wrong?


    Thank you in advance.
    the doer alone learneth. (nietzsche)

  8. #8
    Join Date
    Apr 1999
    Posts
    27,449

    Re: CFile

    Do you really need all of that MFC just to have a function to open, read, and close files? Especially all you have is a console app?

    Why not just use the Windows API file functions -- then you don't need MFC CFile at all.

    Regards,

    Paul McKenzie

  9. #9
    Join Date
    Jun 2004
    Location
    bucharest, ro
    Posts
    53

    Re: CFile

    Thank you for your swift reply.

    Normally I would not need to use CFile, but for my "homework" assignment it was specified as mandatory to use CFile and no other route.
    the doer alone learneth. (nietzsche)

  10. #10
    Join Date
    Jan 2003
    Location
    Cambridge, UK
    Posts
    752

    Re: CFile

    all you need to do is to create simple console app with wizard and check MFC support at some stage (depending which IDE do you use). then e.g. in main() (or _tmain() or whatever else will be generated as entry point) you can write

    Code:
    		CFile file;
    		if ( file.Open(_T("c:\\hello.txt"),CFile::modeCreate|CFile::modeWrite))
    		{
    			// do something
    		}
    Cheers,

    Alex
    Please rate this post if you find it helpful

  11. #11
    Join Date
    Apr 1999
    Posts
    27,449

    Re: CFile

    Quote Originally Posted by s|lent
    Thank you for your swift reply.

    Normally I would not need to use CFile, but for my "homework" assignment it was specified as mandatory to use CFile and no other route.
    Well if you're being taught C++, it isn't being taught correctly:
    Code:
    void main()
    The main() function returns an int, not void.
    Code:
    int main()
    Second, that is really a weird requirement. What is the name of the class that is giving you this homework? Unless it is a class called "Using MFC in a console app" or something similar, I don't understand why using CFile would be a requirement -- it is more of a hindrance IMO if all you have is a console app and all you need is to read a file.

    Regards,

    Paul McKenzie

  12. #12
    Join Date
    Aug 2000
    Location
    West Virginia
    Posts
    7,721

    Re: CFile

    Quote Originally Posted by s|lent


    the error I have been given is:

    error C2664: 'CFile::Open' : cannot convert parameter 1 from 'const char [13]' to 'LPCTSTR'
    Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
    You probably have the setting for UNICODE character set ...

    Code:
    fisier.Open( _T( "c:\\test2.txt" ) , CFile::modeCreate|CFile::modeWrite);

  13. #13
    Join Date
    Jun 2004
    Location
    bucharest, ro
    Posts
    53

    Re: CFile

    that has worked, many thanks.

    I have never seen this "_T" in my google visits to CFile: Is there any good online reference with a good/complete way of providing these parameters to the CFile methods, something which might detail on the "_T" for example?

    I miss its point, does the target file have to be UNICODE all the time?
    the doer alone learneth. (nietzsche)

  14. #14
    Join Date
    Jan 2003
    Location
    Cambridge, UK
    Posts
    752

    Re: CFile

    _T() is just a macro to be expanded into ascii or UNICODE depending on project settings. you can see its definition
    Cheers,

    Alex
    Please rate this post if you find it helpful

  15. #15
    Join Date
    Jun 2004
    Location
    bucharest, ro
    Posts
    53

    Re: CFile

    Ok, here is the problem that I am facing wth:

    (All I need is a point to the right direction not the code for the problem, that I want to do myself)

    I have a txt file with several lines:

    111111, sdsaddsdasd, 2132323213, axaxccasx

    I need to read these lines, one by one and place them into another file. I need to read them one by one because I need to write in the destination file only some parts(tokens) of the initial file.

    What is the actual way I can achieve this? I was trying to make a vector of strings where I would store each line read from the first file, but I do not know how to read line by line. Are there any CFile methods that read a file, line by line so I can store the lines in that vector?

    Thanx.
    the doer alone learneth. (nietzsche)

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured