|
Hi,
You can use CFile, like this you open the file..
char* pszFileName = "c:\\test\\myfile.dat";
CFile myFile;
CFileException fileException;
if ( !myFile.Open( pszFileName, CFile::modeCreate |
CFile::modeReadWrite, &fileException ) )
like this you can read and write..
char szBuffer[256];
UINT nActual = 0;
CFile myFile;
myFile.Write( szBuffer, sizeof( szBuffer ) );
myFile.Seek( 0, CFile::begin );
nActual = myFile.Read( szBuffer, sizeof( szBuffer ) );
Like this you close the file..
myFile.Close();
The price of anything is the amount of life you exchange for it.
Thanks and Regards.
SANTHOSH V
|
|
|
|
|
CStdioFile::ReadString
CStdioFile::WriteString
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
i try both example but nothing is write in file..File is open but data is not write there?
Plz help me
singh
|
|
|
|
|
|
Hi
I more problem when new is came then old line is delete.But i don't want to delete old line..Plz help me
|
|
|
|
|
cpvc++ wrote: Plz help me
F*CK, you don't reply to my questions, and still you're asking for help ?!!!
|
|
|
|
|
Hey what question Man?I am asking first time..
|
|
|
|
|
|
Mr. toxcct
I am not Mr. polop which is start this thread.I am different user and it's post help me and i want some more help me..Sorry for missunderstanding any way my code is here..Pla help me
CStdioFile file;
if (file.Open("\\log.txt", CFile::modeCreate|CFile::modeWrite ))
{
file.WriteString(logfile);
file.WriteString("\n");
}
file.Close();
logfile is CString type which have some information..
Now i am able to write in file but old line is delete when new line write.
Plz help me
|
|
|
|
|
cpvc++ wrote: I am not Mr. polop which is start this thread
sorry, I didn't notice that aspect of the things
The problem in your code is that you're using CFile::modeCreate , but according to the documentation[^], this flag tells to truncate the file if already existing :
MSDN says: CFile::modeCreate
Directs the constructor to create a new file. If the file exists already, it is truncated to 0 length
So, you have to add the flag CFile::modeNoTruncate to counter this undesired behavior.
The use of this flag however keeps the file pointer at the beginning of the file. So if you want to append things at the end, you must call once after CStdioFile::Open() the function CStdioFile::Seek(CFile::end) .
Does the following work better ?
CStdioFile file;
<font color="blue">if</font> (file.Open(_T(<font color="blue">"\\log.txt"</font>), CFile::modeCreate | CFile::modeWrite | CFile::modeNoTruncate)) {
<font color="green">
file.SeekToEnd();
file.WriteString(logfile);
file.WriteString(_T(<font color="blue">"\n"</font>));
file.Close();
}
modified on Thursday, September 4, 2008 6:46 AM
|
|
|
|
|
ok when i am useing your code then i am geting error..Plz help me
error C2660: 'CStdioFile::Open' : function does not take 1 arguments
error C2660: 'CStdioFile::Seek' : function does not take 1 arguments
error C2065: 'logfile' : undeclared identifier1>
error C2660: 'CStdioFile::Open' : function does not take 1 arguments
error C2660: 'CStdioFile::Seek' : function does not take 1 arguments
error C2065: 'logfile' : undeclared identifier
|
|
|
|
|
god, I made a typo.
you shouldn't have read
if (_T(file.Open("\\log.txt"), CFile::modeCreate | CFile::modeWrite | CFile::modeNoTruncate)) {
but this :
if (file.Open(_T("\\log.txt"), CFile::modeCreate | CFile::modeWrite | CFile::modeNoTruncate)) {
I fixed the previous post BTW.
and sorry, I am at work, and I have no compiler, so I couldn't test it before posting...
|
|
|
|
|
i was read but i think both have make same mistake..And mistake is
file.Seek(CFile::end) this is not right and right one is this
file.Seek(0,CFile::end)
Any way thxs for help..
|
|
|
|
|
cpvc++ wrote: this is not right and right one is this
file.Seek(0,CFile::end)
Yes you're right.
BTW, you still can call CFile::SeekToEnd() which takes no parameters, and moves directly to the end of file.
anyway, does it work now for you ?
|
|
|
|
|
Thx's all
I was wrong..
It's working..
THx's for help
singh
|
|
|
|
|
how can i give color to CtabCtrl buttons .......?
|
|
|
|
|
Hello,
I am planning to develop an opensource application which has to work on all three popular platforms (Linx, MAC and Windows). The application will have a core engine which is same for all the platforms and the UI will be different for each platform.
For windows, I plan to use WPF and for LINUX and MAC someother opensource UI framework.
I need to make the core engine as platform independent, hence I plan to write it on C++. How do I start about it? I am fairly new to C++ (I know the basics).
I know MFC is only for windows. Is it possible to develop a library which woks on all platforms using VC++? What are the other alternatives I have?
|
|
|
|
|
Christian Flutcher wrote: For windows, I plan to use WPF and for LINUX and MAC someother opensource UI framework.
Please have a look at the following links. All of them are completely cross-platform:
Visual Component Framework[^] - This one is developed and maintained by one of our fellow CPians, namely Jim Crafton.
WX Widgets[^]
QT[^]
Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche
.·´¯`·->Rajesh<-·´¯`·.
[Microsoft MVP - Visual C++]
|
|
|
|
|
Rajesh R Subramanian wrote:
Visual Component Framework[^] - This one is developed and maintained by one of our fellow CPians, namely Jim Crafton.
WX Widgets[^]
QT[^]
Thanks for that You already suggested these when we had a lounge discussion on the same subject. Thanks anyway.
For writting the core engine, which compiler should I use? I have to make it as a DLL. And is it possible to use the Visual Studio editor even if I am not using MFC/C++ CLI?
|
|
|
|
|
Christian Flutcher wrote: For writting the core engine, which compiler should I use?
On Windows, you may use Visual C++ (Yes, visual studio).
Christian Flutcher wrote: And is it possible to use the Visual Studio editor even if I am not using MFC/C++ CLI?
Usually, there should be a way to get those open source frameworks (like WxWidgets, QT, etc.,) to work on VS IDE itself. After all, VS is just an IDE. Consult with the corresponding websites of those frameworks. But some may have its own IDE and that should not be a problem though - the IDE should work on all platforms, which is better in fact.
Not to mention that you will need to compile your application separately on the all of the target OS for generating the corresponding binaries of that OS.
Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche
.·´¯`·->Rajesh<-·´¯`·.
[Microsoft MVP - Visual C++]
|
|
|
|
|
Rajesh R Subramanian wrote: On Windows, you may use Visual C++ (Yes, visual studio).
I plan to use the borland compiler and use VS as editor. After completing it, I need to compile it for each platform, right? Do you know that compiler allows to create a DLL for that class in windows?
Thanks for taking time to help me. Your replies were really helpful. Thanks again
|
|
|
|
|
Christian Flutcher wrote: I plan to use the borland compiler and use VS as editor.
Is there a specific reason to it? If you are using the VS, then why not use the Visual C++ compiler itself?
Christian Flutcher wrote: After completing it, I need to compile it for each platform, right?
Yes, you will need to compile your code on each and every platform that you plan to deploy it on.
Christian Flutcher wrote: Do you know that compiler allows to create a DLL for that class in windows?
A DLL is also a mere PE File[^], and you will be able to create one with any compiler.
If you need to know how to create a DLL and use it, I will suggest this series of 4 articles written by Hans Dietrich:
http://www.codeproject.com/KB/DLL/XDllPt1.aspx[^] (Links to next parts of the series is on the article itself)
Also, see this: Regular DLL tutorial for beginners[^]
Write back if there's any trouble.
Christian Flutcher wrote: Thanks for taking time to help me. Your replies were really helpful. Thanks again Smile
My pleasure.
Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche
.·´¯`·->Rajesh<-·´¯`·.
[Microsoft MVP - Visual C++]
|
|
|
|
|
Rajesh R Subramanian wrote: Is there a specific reason to it? If you are using the VS, then why not use the Visual C++ compiler itself?
Correct. But this class should compile with other compilers which are in LINUX and MAC. So I think, using VC++ compiler won't allow me to compile the same code on other platforms. Correct me if I am wrong.
|
|
|
|
|
Using VC++ compiler on Windows has nothing to do with compiling on other platforms. If you write portable code, it will compile on any standard-conforming C++ compiler including VC++.
|
|
|
|
|
Okay. So I shoud not use any MFC classes. Use plain C++ classes for it, right?
|
|
|
|