-
February 16th, 2007, 06:40 AM
#1
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)
-
February 16th, 2007, 07:08 AM
#2
Re: CFile
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++.
-
February 16th, 2007, 07:13 AM
#3
Re: CFile
set the runtime library to multi threaded (MT) and include afx.h.
Regards
Laitinen
-
February 16th, 2007, 08:26 AM
#4
-
February 16th, 2007, 09:08 AM
#5
Re: CFile
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)
-
February 16th, 2007, 02:05 PM
#6
Re: CFile
In VC6 it's under the C/C++ tab, Code Generation category.
-
February 17th, 2007, 07:59 PM
#7
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)
-
February 17th, 2007, 08:03 PM
#8
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
-
February 17th, 2007, 08:06 PM
#9
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)
-
February 17th, 2007, 08:10 PM
#10
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
-
February 17th, 2007, 08:11 PM
#11
Re: CFile
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:
The main() function returns an int, not void.
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
-
February 17th, 2007, 08:20 PM
#12
Re: CFile
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);
-
February 17th, 2007, 08:35 PM
#13
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)
-
February 17th, 2007, 08:44 PM
#14
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
-
February 18th, 2007, 04:55 AM
#15
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)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|