|
the file is not being created for some reason then. If the file exists, the code on debug drops into the file exists section (.is_open is valid), but if I delete the file and step through it into the "does not exist" block (.is_open has failed), I don't see the file being created and written to.
|
|
|
|
|
FileDataStream.open(fileName, ofstream::out | ofstream::in);
aha, it shouldn't be created unless there is the flag ofstream::in. Remove this flag; it makes the ofstream to think the file exists. Moreover, you even do not need ofstream::out flag; this flag is by default.
If you want read from a file then prepare a separate ifstream object.
And a minor note, why to type ofstream::out while you can shortly do ios::out. Actually, out and in are from ios.
--
=====
Arman
|
|
|
|
|
Hi Arman, well I must be misunderstanding it then because this is my code. When i step through it
"fileName" is to a valid path, because if I make the file exist, the code drops into the file exists section. If I delete the file and rerun it, it drops into the file does not exist section and it can't have been created because nothing is being written to it. Also, if the default action of ".open" is to create it if not found, where is the empty file, and why is it even going into the "file does not exist" section of the if/else??
fstream FileDataStream;
FileDataStream.open(fileName);
if(FileDataStream.is_open())
{
// file exists
// Read Data
// Append Data
}
else
{
// file does not exist
// WriteHeader
FileDataStream<<'!'<
|
|
|
|
|
ldsdbomber wrote: FileDataStream.open(fileName);
What is default mode for the fstream::open() method? If you are unsure, specify an explicit argument.
ldsdbomber wrote: when it does not exist, it does not create anything.
Do you have permission to create files in that folder?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I can create files manually via windows explorer, so unless there is a separate security issue that only affects files created through my app I don't know why it would be a problem.
I took the modes out of the fstream as the other reply indicated that they weren't needed but it didn't work with the ::in or ::out flags specified either
I got it to do something by adding this
fstream newFile;
CFileDialog fileBrowser(FALSE,".txt",NULL,OFN_OVERWRITEPROMPT,"Geske Energy Data Files (*.dat)|*.dat|",NULL);
int ret = fileBrowser.DoModal();
newFile.open (fileBrowser.GetFileName());
// WriteHeader
newFile<<'!'<<"hjhjh"<
|
|
|
|
|
ldsdbomber wrote: I took the modes out of the fstream as the other reply indicated that they weren't needed but it didn't work with the ::in or ::out flags specified either
I've got an older version of the STL, and it shows that fstream::open() has no default mode -- a mode must be supplied. That apparently is not the case with you or you would have received a compiler error. An ostream object, however, defaults to out .
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
thanks. the problem is I want to create a new file only if it doesn't exist and I can't get that to work. Unless I am being an idiot, the flag I need is ios::nocreate and this can be ORed in with the out flag
i.e.
FileDataStream.open(fileName, ofstream::out | ios::nocreate);
but when i do this, it is still making the file even when it doesn't exist. I don't know why one flag is ofstream and the other is ios, but ofstream::nocreate didn't seem to work.
Maybe I am just getting in a pickle with this, but I couldn't find a useful example that I could follow along, surely "open file for appending, unless it's not there in which case make a new one and write to it" must be a very commonly done thing!
|
|
|
|
|
Hopefully a simple question.
At design time what are the units of the measurements at the bottom left of the screen? Basically at present I want a dialog that fills the entire width of the screen (1600x1200), I can set up and populate this at runtime but would prefer to do it at design time.
cheers,
Andy
|
|
|
|
|
I assume you are talking about DLU ( Dialog Logical Unit ).
google about them.
|
|
|
|
|
Hope I understood your question
Do you need to Width and height of the screen does GetSystemMetrics(SM_CXSCREEN/SM_CYSCREEN); your answer?
|
|
|
|
|
open your dialog in resource editor and check for property "maximize"
|
|
|
|
|
mcsherry wrote: Basically I want a dialog that fills the entire width of the screen (1600x1200), I can set up and populate this at runtime but would prefer to do it at design time.
This is almost assuredly going to fail. If you want a full-screen dialog, do it at runtime. Then it will work on any system, at any resolution, using any font. Otherwise, the only system that it is guaranteed to work on is the one you designed it on.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
hello!!!
when i protect file ....the preview of a file should be displayed ...means
file should be played or displayed in a rectangle displayed on window while protecting
|
|
|
|
|
What do you mean by protecting and what do you mean by displaying the file ? And what do you mean by preview ?
Which kind of files ?
|
|
|
|
|
Ahmm... but here is there no one with telepathy??? :P
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
|
|
|
|
|
Nelek wrote: Ahmm... but here is there no one with telepathy???
Yes, but not on days that end in 'y'.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
DavidCrow wrote: but not on days that end in 'y'
Why?
|
|
|
|
|
Nelek wrote: but here is there no one with telepathy???
Hah! I knew you were going to say that!
Oh wait, thats psychic powers...
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
More explain will be helpfuls.
|
|
|
|
|
Hi Friends
I want to know how i get ID of common controls used in project.I am using CFileOpen class for Open file dialog file. I want ID's of each control used on that common controls such as static text "Look in", "File of Type" etc. I want to know these ID because by using these ID i want to change font of common controls.
Thanks in Advance
Atul
|
|
|
|
|
Take a look in the path: .\Microsoft Visual Studio\VC98\MFC\SRC
Files: DLGFILE.cpp, DOCMGR.cpp, PPGPICT.cpp
One is its implementation and in the other two there are functions that use and config the CFileDialog
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
|
|
|
|
|
For runtime observations;
EnumChildWindows
GetDlgCtrlID
--
=====
Arman
|
|
|
|
|
Look in dlgs.h .
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I have got problem. How can I create under application, word file with text, which I want put there.
Does anybody now how to do it?
Thx
|
|
|
|
|
MS Word's Doc format, as much as I know, is not a free format, so it's not strange that there is not an article about it.
However it is possible to use reverse engineering or other hacks to find out the format of the file, and I'll not be surprised if I see some one did that already. Searching the web might help you find the format, after that it's as easy as creating a file with similar format and putting text into true order.
// "Life is very short and is very fragile also." Yanni while (I'm_alive) { cout<<"I love programming."; }
|
|
|
|