|
vector <CMyTrailer> m_Item;
vector <CMyTrailer> m_MFG;
...fill...
m_Item.insert( m_Item.end(), m_MFG.begin(), m_MFG.end());
BTW.
the name of the function is push_back
Let's think the unthinkable, let's do the undoable, let's prepare to grapple with the ineffable itself, and see if we may not eff it after all. Douglas Adams, "Dirk Gently's Holistic Detective Agency"
|
|
|
|
|
but for this, you have to iterate yourself thru the vector to be copied...
STL provide very powerful algorithms. check my other post.
|
|
|
|
|
std::vector<int> v1;
std::vector<int> v2;
std::copy(v1.begin(), v1.end(), std::back_inserter(v2));
|
|
|
|
|
How exactly does your code work? I'm not too famular with vector(S) or the STL in general. Will std::copy copy anything or is it just for vector(s)? The way you presented: std::copy(v1.begin(), v1.end(), std::back_inserter(v2)); I thinkl thats what I'm looking for; but I'm not sure. I want the (in your example) v1 vector loaded at the end of it's current data: with the v2 vector (beginning at the front of v2(begin()) to v2's end (end()).
Also How do I show the data in each CMyTrailer::m_csData ? (console example is sufficient). I want to verify that everything is doing what I want it to do before I placed it in a ListBox in my program.
Thanks,
A C++ programming language novice, but striving to learn
-- modified at 14:12 Thursday 22nd November, 2007
What I mean, is I don't know how to extract CMyTrailer::m_csData from each iteration of the vector.
|
|
|
|
|
ok, i'm detailing a bit more.
the STL is a set of classes, all in the standard of C++.
some of the classes are containers (vector is one of these).
some other classes are called algorithms. they are designed to do common actions on the containers. copying a part of a container into another is one of those common things we can except of it.
if you have a vector v1, which contains say {4, 7, -1} and a vector v2, which has {2, 9}, then you just copy the line of code just like I did and after that, v2 will contain {2, 9, 4, 7, -1}.
actually, v1 is copied entierely because i told the copy() algorithm to do so. i said to start the copy from the first element of v1 (v1.begin()) and to copy to the end (v1.end()).
also, the elements of v1 are copied at the end of v2 because I use the back_inserter() alorithm, which is designed to insert at the back.
|
|
|
|
|
void CTrlMasterDlg::AddVecItem(const ITEM& vec)
{
// vector to be copied: iterator
//vector<CMyTrailer>::iterator m_ITItemvec;
//vector to hold all copied data: id m_Item
// set iterator at back of m_Item:
m_ITItem = m_Item.end();
// set vector to be copied at the front of it's vector:
m_ITItemvec = vec.begin();
while(m_ITItemvec != vec.end())
{
/*
m_Item.pushback(vec.);
m_ITItemvec++;
*/
// Is this right?
//std::copy(v1.begin(), v1.end(), std::back_inserter(v2));
std::copy(vec.begin(),vec.end(),back_insertor(m_Item));
}
}
So using my vectors: if I want everything from from vec to go into m_Item vector start at m_Itetm's last data(MyTrailer), is the above code correct? If not would you show me?
A C++ programming language novice, but striving to learn
|
|
|
|
|
actually, where you're wrong is that you don't need to iterate yourself. the std::copy() algorithm does it for you :
void CTrlMasterDlg::AddVecItem(const ITEM& vec) {
std::copy(vec.begin(), vec.end(), std::back_insertor(m_Item));
}
and for your personnal knowledge, this was quite the same as the following :
void CTrlMasterDlg::AddVecItem(const ITEM& vec) {
for (ITEM::iterator it = vec.begin(); it != vec.end(); it++) {
m_Item.push_back(*it);
}
}
|
|
|
|
|
I certainly appreciate all of your help. I'm new to the STL; but I want to learn it. I really only have CodeProject as a learning vehicle. Limited resources if you get my drift.
One other question. How do I get the CMyTrailer::m_csData Data out of the vector? What the vector does is copy the data the User has entered from various Wizard pages(hence the need to copy that data into one vector) and display it on the final Wizard page; then save it to file, and other things. I'm a little lost as to how to get each ("*it") in your example to become the class CMyTrailer. Could you explain how to get each CMyTrailer out of the vector?
Thanks in advance.
A C++ programming language novice, but striving to learn
|
|
|
|
|
I don't know what is m_csData, but it's a member of your class CMyTrailer, which class has several instances into the vector. you agree with that ?
i'm not sure to understand exactly why you're trying to access m_csData; not in the copy achievement, right ?
anyway, let's say you have an iterator on the vector :
ITEM::iterator it = vec.begin();
like i declared it, and initialized it, it is now an iterator which can go thru ITEM's elements, and is told to be placed on the first element of the vector.
basically, you can see an iterator as an "involved" pointer. just remember that, like pointers, you access the element pointed to by "dereferencing" it : *it
so, *it now returns the CMyTrailer element pointed to by it.
as m_csData is public, you can just access it like that :
(*it).m_csData;
or even better
it->m_csData;
for your learning, here is THE web site reference for STL : http://www.sgi.com/tech/stl/[^]
also, you can find at codeproject some good articles, like This One[^].
but feel free to continue asking me if you need
|
|
|
|
|
I tried to do this: std::vector<CString> m_Item; but the compiler wouldn't let me. to work around that I created the CMyTrialer class whose only purpose is to have a CString (m_csData) as it's only purpose. the compiler accepted that but when I just put vector<CString> the compiler said error: CString is not a class, union,etc. so I just created CMyTrailer to hold a CString and the compiler accepted that.
I will take each of the CMyTrailer.m_csData data and put them into a listbox on the final page of the Wizard.
A C++ programming language novice, but striving to learn
|
|
|
|
|
if you're dealing with STL, why do you go to the end and use std::string, rather that mixing STL and MFC ?
std::vector<std::string> would have done your job though.
|
|
|
|
|
I got the same compiler error when I used std::vector<string> m_Item. Thats why I tried std::vector<CString> m_Item.
A C++ programming language novice, but striving to learn
|
|
|
|
|
maybe because you didn't include the correct headers...
have you thought of #include <string> ?
|
|
|
|
|
Hi All,
I'm having a win32 dll. I need to provide a version number for the DLL.
How can we achieve this through code?
I'm using VC++6.0 for building the dll.
Many thanks,
Rajesh
|
|
|
|
|
|
Hi,
I'm actually writing a CLIENT/SERVER TCP/IPv6 application, under Microsoft Visual Studio C++. In which the SERVER is a file server application and the CLIENT is a "Multiple Document Interface (MDI)" and "RichEdit Text" application that can open multiple files from the server.
I would like to add a Toolbar window into my MDI frame window, to do this, I've created the Toolbar window with the "CreateToolBarEx" function.
But the created Toolbar window is located in the client area of the MDI frame window and each time a new MDI child window is created to hold a new document, it erases the Toolbar window in the client area.
My question is how can I do :
1) To change the client area size so that fits
height(MDI Frame window) - height(Toolbar window)
OR
2) To include the Toolbar window into the
non-client area like the Menubar and the Titlebar
So that the MDI client window can't anymore erase the Toolbar window in the client area.
Thanks,
Alain NGUYEN
|
|
|
|
|
add a class derived from ccontrolbar.
and then use dockcontrolbar().
prasann
who else
|
|
|
|
|
Hi all,
it's very helpful for me. i have created an application to install an printer Locally through INF file.when a call AddPrinter() function it fails with error code 126(specified module could not be found) Although i have initalise all the parameter as mention in MSDN( You must specify non-NULL values for the pPrinterName, pPortName, pDriverName, and pPrintProcessor members of this structure before calling AddPrinter. ). but it failed and initialisation is correct for that from my end......is there any reson to fails this function.
plz help me.Thanks in Advance.
Ashish
|
|
|
|
|
Have you checked the path to the *.inf file?
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?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
|
|
|
|
|
Hi,
Is that possible to run an executable file that is part of a data file by passing the begining (disk offset) inside this data file ?
Regards,
sdancer75
|
|
|
|
|
I've just been having a look at CreateProcess, and the simple answer is...
NO.
But - you can be clever...
There's nothing stopping you making a temp file from this arbitrary data, and then running create process on it.
The clever bit is to create the temp file with the FILE_FLAG_DELETE_ON_CLOSE flag set. So, after the process is started, close your handle to the file.
When the process finishes - that will close it's handle, and *poof* - file gone.
Iain.
ps. I haven't actually tried this myself, it's from reading. I look forward to your results.
pps. doing a google search for FILE_FLAG_DELETE_ON_CLOSE may give you very clear sample code.
|
|
|
|
|
|
Well, that example does explicitly say its for assemblies, etc - so it's not really any use to you.
I'd break your problem into steps (classic programming!)
1/ Get a pointer to a resource in your software (FindReource, etc).
2/ Then work out how to make temporary filenames
3/ Create a temp file with the delete-on-close flag - sleep - alt tab to explorer and go "wow, it's there!"
3a/ close the handle... alt tab to explorer and go "wow, it's gone!"
4/ Now try the trick with an executable - and make sure you use appropriate sharing flags when you create the file.
4a/ try running your executable manually between creation and deletion.
5/ Move on to Create Process and away you go!
All of the above could be with MFC, Win32.. etc. In the end it will end up as Win32 calls.
Iain.
|
|
|
|
|
ok Iain thanks.
Right now it works in this way you described. All I wanted is to avoid temp files.
Anyway, I can not think any other way to do that.
Regards,
sdancer75
|
|
|
|
|
Hi
How to find that a CWnd pointer is a CEdit* or a CButton* or ant other Cwnd drived classes?
I tested it this way :
if(pWnd->GetRuntimeClass() == RUNTIME_CLASS(CEdit))<br />
pWnd->ShowWindow(SW_HIDE);
but it did not work.
Thanks
|
|
|
|