|
The map is (long, char*). I get a char* buffer tempB from a CFile read, of size nSize .
CAn I do aMap[nSize] = tempB ? i.e. assign it with the = sign?
or do I have to allocate memory for the maps second element or something and do a strcpy?
I would have avoided char* and used CStrings but it looks like the Write for CFile needs a pointer to a buffer....
In case my question isnt clear...we cant assign char* with the = sign, it has to be strcpy. SO in the case of my map, do I allocate ,memory to *it.second() and strcpy?
Appreciate your help,
ns
|
|
|
|
|
You can still use CString.
<br />
CString csWrite(_T("Hello World"));<br />
CFile cFile;<br />
<br />
cFile.Open(...);<br />
cFile.Write((void*)(LPCTSTR)csWrite, csWrite.GetLength());
|
|
|
|
|
Thanks so much for telling me CString works! I was going through hoops wqith strcpy and all that mess. Thank you very very much!
Appreciate your help,
ns
|
|
|
|
|
Can I use the same trick with Read?
CString abc;
cFile.Read((void*)(LPCTSTR)abc, abc.GetLength());
Appreciate your help,
ns
|
|
|
|
|
int n=S.GetLength(); // this is icky
S.ReleaseBuffer(File.Read(S.GetBuffer(n),n));
|
|
|
|
|
Oh. So I dont need the LPTCTSR thing for read because GetBuffer returns the pointer to the string? Thanks for the compact coding.
Appreciate your help,
ns
|
|
|
|
|
Argh. I can't stand it any longer.
Just leaving with a note that the above
is "icky" wont make the itch go away.
I wrote something knowingly bad above.
This may be pedantic but I gotta get rid of the itch.
GetBuffer returns a pointer to a buffer to which you may
safely store directly into the CString object, but using
a CString whose length happens to match the amount of
data you are reading in is just bad practice.
If one knows the amount of data to be read, then one
should specify it explicitly. e.g.
int n=128;
CString Planet;<br />
Planet.ReleaseBuffer(File.Read(Planet.GetBuffer(n),n)!=n?0:-1);
Better yet, create structures that mirror the fixed length
portions of the file and read them in entirety. e.g.
struct Names<br />
{<br />
enum {NAMESIZE=128};<br />
char Planet[NAMESIZE];<br />
char System[NAMESIZE];<br />
};<br />
<br />
ABC MyNames;<br />
VERIFY(File.Read(&MyNames,sizeof(MyNames))==sizeof(MyNames));
and if you need it in a CString later:
MyNames.Planet[NAMESIZE-1]=0;
CString S=MyNames.Planet;
|
|
|
|
|
Thanks! That gives me a lot to think about...
Appreciate your help,
ns
|
|
|
|
|
I have a map object:
std::map [long , CString] m_MapForMerge;
(forgot how to replace angled brackets for definition of map for CP)
Its just declared but not created yet.
I get the values of the its two components in a loop, nSize and tempBufString . I want to fill the map with these two values. Is this the way to do it?
tempBuffer = new char[nSize];
ReadPFile(sPathName, tempBuffer);
tempBufString = tempBuffer;
m_MapForMerge[nSize] = tempBufString;
or should it be:
tempBufString = m_MapForMerge[nSize];
Appreciate your help,
ns
|
|
|
|
|
The first way is the correct one.
|
|
|
|
|
careful with map inserts....duplicate keys will bounce off of a map [if someone knows how to 'turn this off' please clue me in ]....maybe you know that however.....very careful map users will use a 'find' call first to make sure the map 'slot' is available....if 'find' comes back != end() then something is already at that location in the map and you may have to do some extra logic to deal with that case...
Just trying to keep the forces of entropy at bay
|
|
|
|
|
RedZenBird wrote:
duplicate keys will bounce off of a map [if someone knows how to 'turn this off' please clue me in ]
Do you mean 'std::multimap'?
It can hold the same key more than once, but finding an entry gets slightly more complicated, as you cant possibly know how many entrys gou get.
|
|
|
|
|
Never used them, but multimaps accept duplicate keys I believe...
Thanks so much for the responses. I finally had to use a vector with a two element structure type precisely because of bouncing off of duplicate keys.
Appreciate your help,
ns
|
|
|
|
|
I want to create array of CArray.
If I have this below CArray
CArray<unsigned char,="" unsigned="" char=""> m_data;
I want to create Array of m_data. Do you know how to do that ?
|
|
|
|
|
CArray m_array [ 5 ] ;
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
I'm working toward checking this out myself, but am curious. If I write a buffer to a CFile object, then Write buffer#2, followed by buffer#3, all before closing the file, one after another, the output file wil have the three buffers concatenated. Is that correct? I'll have three binary buffers so I dont know if I can tell if they are in order etc....want to be sure. They dont start afresh at the beginning of the CFile at each Write, right?
Thanks,
ns
|
|
|
|
|
no they dont start at the begining each time, they get concatenated
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
Thanks again! Its great to have you around!
Appeciate it,
ns
|
|
|
|
|
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
I am trying to draw an xy scatter graph using MSchart (ActiveX) but there is only documentation for VB. I want to draw a y=x^2 graph. This is what I have but returns an error saying "Index is out of bounds".
m_chart.GetPlot().GetAxis(VtChAxisIdX, v).GetAxisTitle().SetText("x");
m_chart.SetTitleText("Simple graph");
m_chart.SetColumnCount(4);
m_chart.SetRowCount(10);
int x,y;
for(y=0;y<4;y++){
m_chart.SetColumn(y);
for(x=0;x<10;x++){
m_chart.SetRow(x);
int a = x*y;
m_chart.SetColumn(a);
}
}
A small example would be helpful
Any ideas?
|
|
|
|
|
Try setting the index to 1 instead of 0:
for(y=1;y<=4;y++){ ...
for(x=1;x<=10;x++){ ...
|
|
|
|
|
I get the same error, I think it has something to do with m_chart.SetColumn().
I have a feeling this may not be the right Function but don't know what I'd put in it's place.
|
|
|
|
|
http://softwaredev.earthweb.com/msnet/vc/article/0,,12081_629511,00.html Sorry outside CP
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
Hi, I found this article yesterday and this works fine for a bar graph. I tried to manipulate this for an xy scatter graph without much luck. The problem lies in setting x and y values.
|
|
|
|
|
Folks,
Does anyone know who to disable the accelerator keys temporarily in a MFC application? I would like to disable the functionality of the entire menu bar when doing lengthy operation. Currently, I call the following function to disable the menu bar.
CMainFrame::EnableWindow ( FALSE );
Apparently, it works ok. The menu bar is grayed out and does not response to mouse clicks. However, when as user press "Alt", the menu bar turn ON again and start to operate. It seems like the "Alt" button enable the menu bar.
Anyway, to disable accelerator keys feature temporarily?
Thank you.
bluntagain
|
|
|
|