|
you might want to investigate Iterators
led mike
|
|
|
|
|
This line:
vector<byte> vec[45]; </byte> does not declare a vector. It declares an array of vectors. From your description, I don't think that's what you intended.
But if you have a vector, its storage is guaranteed to be contiguous, so taking the address of vec[0] is fine. Last modified: 7hrs 19mins after originally posted --
|
|
|
|
|
act_x wrote: if i have an STL vector
vector<BYTE> vec[45] ;
No you don't: you have an array of 45 vectors!
act_x wrote: BYTE * p = reinterpret_cast<BYTE*>(&vec[0]);
NOTE: Underlined brackets were added by me. They are needed.
This reinterpret_cast is not needed as the type of &vec[0] is already a BYTE* .
act_x wrote: is it safe to assume that the pointer p can be used safely even though its pointing to the address of a vector ?
It isn't pointing to a vector but rather an element contained in the vector.
Steve
|
|
|
|
|
|
|
You can also browse thru the link
http://msdn2.microsoft.com/en-us/library/ms997646.aspx
|
|
|
|
|
Thank you friends for your nice and quick reply.You have solved my problem.Thanks again !!!
Regards
Avinash Gupta
1st Year B-TECH Student(CSE),
ITER India.
|
|
|
|
|
Hi,
Can anybody explain to me how to be able to save and also print the drawing(using GDI) in a CWnd custom control in a dialog box.There are a few custom controls that display different part of the total drawing to be saved and maybe printed and one of them has a scrollbar. Is there any article that i can refer to?
|
|
|
|
|
Hi there,
I have a .txt file and characters was read from it and was put into character arrays. However, for example if the int 22 and 4 is read from the file and was put into an array of integers, how can I write it in a file using fstream.write(). As far as i know, to use this function, the output should be in character format. Therefore, may i know how to change the integer into character array of '22' and '4' and put into fstream.write().
Thanks for any suggestions!
|
|
|
|
|
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
|
|
|
|