|
I hope this help
Streams were originally designed for text, so the default output mode is text. In text mode, the newline character (hexadecimal 10) expands to a carriage return–linefeed (16-bit only). The expansion can cause problems, as shown here:
#include <fstream.h>
int iarray[2] = { 99, 10 };
void main()
{
ofstream os( "test.dat" );
os.write( (char *) iarray, sizeof( iarray ) );
}
You might expect this program to output the byte sequence { 99, 0, 10, 0 }; instead, it outputs { 99, 0, 13, 10, 0 }, which causes problems for a program expecting binary input. If you need true binary output, in which characters are written untranslated, you have several choices:
Construct a stream as usual, then use the setmode member function, which changes the mode after the file is opened:
ofstream ofs ( "test.dat" );
ofs.setmode( filebuf::binary );
ofs.write( char*iarray, 4 ); // Exactly 4 bytes written
Specify binary output by using the ofstream constuctor mode argument:
#include <fstream.h>
#include <fcntl.h>
#include <io.h>
int iarray[2] = { 99, 10 };
void main()
{
ofstream os( "test.dat", ios::binary );
ofs.write( iarray, 4 ); // Exactly 4 bytes written
}
Use the binary manipulator instead of the setmode member function:
ofs << binary;
Use the text manipulator to switch the stream to text translation mode.
Open the file using the run-time _open function with a binary mode flag:
filedesc fd = _open( "test.dat",
_O_BINARY | _O_CREAT | _O_WRONLY );
ofstream ofs( fd );
ofs.write( ( char* ) iarray, 4 ); // Exactly 4 bytes written
|
|
|
|
|
I'm not exactly sure what you are asking, but
<br />
#include <fstream><br />
using namespace std;<br />
<br />
ofstream out("x.txt");<br />
<br />
int n = 22;<br />
int m = 4;<br />
<br />
out << n << endl;
out << m << endl;
out << "n = " << n << ", m = " << m << endl;
<br />
results in the following three lines of output:
<br />
22<br />
4<br />
n = 22, m = 4<br />
Peter
"Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."
|
|
|
|
|
Hi Guys
I've got my CMyFormView class
I define a Dialog and Create a Class for this dialog called CMyDialog
From CMyFormView I call an instance of CMyDialog
Ex:
.
.
.
CMyDialog dlgTest;
dlgTest.DoModal();
.
.
.
What's the right way to acces from inside dlgTest the CMyFormView members? (I could continue the question with... ...to avoid that each time that I touch the CMyDialog.h the complete app recompiles ?)
Ex:
BOOL CMyDialog::OnInitDialog()
{
CDialog::OnInitDialog();
// Write code here to acces m_nNumber a int variable declared in CMyFormView.h
return TRUE;
}
Thanks
|
|
|
|
|
doctorpi wrote: What's the right way to acces from inside dlgTest the CMyFormView members?
The dialog should not access the View members. See the Model-View-Controller Design Pattern.
led mike
|
|
|
|
|
Thanks, I knew I missed something
|
|
|
|
|
Just one question then.
If I want to modify from the CMyDialog the CDocument it's mandatory include the CMyDocument.h ?
Then always the complete app is recompiled if I add a member to my CMyDialog?
And then If CMyDialog affects CMyFormView (through CMyDocument) I have to update with Updateallviews from CMyDocument?
Thanks
-- modified at 14:31 Wednesday 11th April, 2007
|
|
|
|
|
doctorpi wrote: it's mandatory include the CMyDocument.h ?
Not mandatory. You can create a Controller for the Dialog that isolates it from the document.
led mike
|
|
|
|
|
I am using MSXML2::IXMLDOMDocument2Ptr to generate an XMl file.
Is there a property that i can set to have the data in the file indented?
|
|
|
|
|
LCI wrote: to generate an XMl file.
LCI wrote: Is there a property that i can set to have the data in the file indented?
I don't think so. If you are using MSXML DOM to "read" in an existing file with indentation then you can use the preserveWhiteSpace property so that if you save it out again it will be indented. But when you create the XML using the API like createElement(..) etc, no. However I think you can use a XSLT transform to produce the indented format. I can't remember all the details but look at TOPXml.com for them.
led mike
|
|
|
|
|
What is the difference in terms of code generation with these two switches? I understand one if for DLL code and one for Multithread code, but it seems that this means I need to generate four static library versions with each library (six if I include single threaded), since I need a release and debug version.
Are people really generating six versions of each static library or am I just missing something important?
|
|
|
|
|
When you specify /MD the compiler will link MSVCRT.LIB(MSVCRT.dll/MSVCR71.dll must be available at runtime) to your object code. If you use /MT the compiler will link the static version of C runtime (LIBCMT.lib) to your application. There is no need for you to generate four static library versions.
You can choose either of these two. Multi-threaded runtime DLL Version(/MD) - Or Multi-threaded runtime LIB version(/MT).
Cheers
-- modified at 6:03 Thursday 12th April, 2007
|
|
|
|
|
I'm making a program that reads data from a device. The data is then used to make a graph in real time. The problem I'm having right now is that when I open any window on top of the graph it erases everything. How do I solve this problem? Any suggestions? Thanks
------------------------
Impossible is Nothing
|
|
|
|
|
You need to save your data somewhere and paint everything in response to the WM_PAINT message only.
Whenever a part of your window needs to be repainted, you will receive a WM_PAINT message and you need to do the drawing there, and only there !
|
|
|
|
|
I was thinking, if it was possible to know when the window went out of focus, I could copy that section of the screen into the clipboard, and then repaste it when the WM_PAINT was called.. wouldn't that be easier, if its possible that is
------------------------
Impossible is Nothing
|
|
|
|
|
nevermind, ur suggestion worked out perfectly, and it wasn't nearly as difficult as i thought it would be. Thanks!
------------------------
Impossible is Nothing
|
|
|
|
|
ok I'm having another problem tho, It seems sometimes it jus stops painting. I don't know why this is happening, but by minimizing and restoring the program it starts to work again. Anyone know why this might happen?
------------------------
Impossible is Nothing
|
|
|
|
|
One message to reply to all your questions
First, your suggestion of using the clipboard when the window loose focus is not really good (it is even very scary): imagine that all applications will do that. Do you imagine what a mess it would be ? And the poor user which desperately tries to copy/paste something
In fact, once you understand the philosophy, everything makes perfect sense. I suggest that you google to find some tutorials about win32 programming (you'll probably find some usefull articles on this website). If you plan to program in win32, it is highly recommanded.
Now, for your last question: in fact the WM_PAINT message is not sent continuously: it is sent only when your window needs to be repainted (so when you minimize it, when something comes in front of it, ...). But, if you need to refresh it (for example because new data needs to be displayed), you need to invalidate it, which will cause a WM_PAINT message to be sent. For that, you can call InvalidateRect[^]
While searching for the link to this function, I came upon this link[^] which is probably what you need to get started.
Enjoy
|
|
|
|
|
Hello,
I've tried the follwing code. everything works fine except conversion from _variant_t to char*.
Any idea of how to do it?
Many thanks for your advice.
int yy = 4;
int zz = 1024;
float ff = 13589.025;
char* chh = "MyString";
_variant_t** test = new _variant_t*[4];
for(int i= 0; i
|
|
|
|
|
Arris7 wrote: Any idea of how to do it?
_variant_t var(_T("hello"));
CW2A ansiBuffer((_bstr_t)var);
cout << ansiBuffer << endl;
led mike
|
|
|
|
|
I wanted to try Visual Studio Express as a debugging medium.
I brought over a project and tried to compile it.
It complained that it couldn't find afxwin.h which is all the MFC core stuff. I looked around and couldn't find it either on that computer.
My question is: can I add something to make the express edition support MFC?
Thanks,
Ilan
|
|
|
|
|
IlanTal wrote: does visual studio express support mfc?
no
|
|
|
|
|
I am new to VC++.Can anyone tell about the concept COM with MFC.PLZ Give any article And sample mfc program with com.
|
|
|
|
|
Is the search engine broken?
Peter
"Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."
|
|
|
|
|
See these[^] articles are helpfuls?
|
|
|
|
|
Thank you
|
|
|
|