|
I have a vector vec of structures. The structure has two members: a long nSize, and a CString fileName.
Now I get these two values on the fly and want to push them onto the vector. Had it been a vector of a single variable, I'd just do vec.push_back(myVAr) . But how do I push_back two elements of my structure into a single vector element?
Appreciate your help,
ns
|
|
|
|
|
Make sure your structure has a constructor which inits the members, like foo(long sz, CString name):nSize(sz), fileName(name).
Then, do something like:
vec.push_back(foo(sz, name));
"If at any time I announce that a nation or kingdom is to be uprooted, torn down and destroyed, and if that nation I warned repents of its evil, then I will relent and not inflict on it the disaster I had planned. And if at another time I announce that a nation or kingdom is to be built up and planted, and if it does evil in my sight and does not obey me, then I will reconsider the good I had intended to do for it." -- Jeremiah 18:7-10 (God, commenting on the value of the United Nations)
|
|
|
|
|
....some thing like:
#include <string>
#include <vector>
using namespace std;
// defined types
//
typedef struct _tagMyThing
{
// make this whatever you want.....for ex:
long lValue;
string oValue;
}
MY_THING, *P_MY_THING;
typedef vector< P_MY_THING > MY_VECTOR;
typedef MY_VECTOR::iterator MY_VECTOR_ITER;
// declare variable of type MY_VECTOR
//
MY_VECTOR m_oVector;
// fill it....
//
P_MY_THING pxThing = new MY_THING;
...
...
m_oVector.push_back( pxThing );
// looping...
MY_VECTOR_ITER oIter;
for( oIter = m_oVector.begin();
oIter != m_oVector.end();
oIter++ )
{
P_MY_THING = (*oIter);
...
...
}
Just trying to keep the forces of entropy at bay
|
|
|
|
|
I guess you are showing how to 'read' it back out...
MY_VECTOR_ITER oIter;
for( oIter = m_oVector.begin();
oIter != m_oVector.end();
oIter++ )
{
P_MY_THING = (*oIter);
...
...
}
This line is puzzling me:
P_MY_THING = (*oIter);
Its assigning to a type? MAybe you meant P_MY_THING abc = (*oIter);
??
A big thank you for the loading part!
Appreciate your help,
ns
|
|
|
|
|
yeah...that was a typo on my part...saw it after i pushed the 'submit button' .... good though that you got what i *meant* there
Just trying to keep the forces of entropy at bay
|
|
|
|
|
What I need to do is create a form view SDI app that has two different forms seperated by a splitter control. Well maybe I do. What I need is a top window that is stationary and a lower window that the user can scroll. What it is is a form that I want the header to always stay on top and in view. Just like some excel sheets do. Is this possible? What is the easiest way of implimenting this? I already have an SDI form view with a splitter control but the 2 panes are of the same window. I have already done a few searches but I think I am looking for the wrong thing. Thanks for your help.
Darroll
Not one person lives in the present. Only the past. I can prove it.
|
|
|
|
|
Check out: Reusable base class for SplitterWnd here in CodeProject. What you can do is not allow the top form to be resized in the class by handling WM_SIZE appropriately, and just swap out the bottom pane.
"If at any time I announce that a nation or kingdom is to be uprooted, torn down and destroyed, and if that nation I warned repents of its evil, then I will relent and not inflict on it the disaster I had planned. And if at another time I announce that a nation or kingdom is to be built up and planted, and if it does evil in my sight and does not obey me, then I will reconsider the good I had intended to do for it." -- Jeremiah 18:7-10 (God, commenting on the value of the United Nations)
|
|
|
|
|
Thank you. I was so new at SDI FormView apps, too many Dialog apps, I missed that whole section. Thank you.
Darroll
Not one person lives in the present. Only the past. I can prove it.
|
|
|
|
|
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 ) ;
|
|
|
|