|
Depends. On some containers, like vector , any iterator becomes invalid (or is not guaranteed to remain valid) after adding/removing data. For list s, on the other hand, iterators remain valid (unless you erase the very object the iterator is pointing to, of course.) Check the docs for more info on each particular container, this kind of things are thouroughly specified.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
In this case i was using a map and i was thinking about doing something like this
iterator itBegin=map.begin();
iterator itEnd=map.end()
for(it=itBegin;it!=itEnd;++it)
{
AddToMap();
}
to add to the map but not loop trough the new added items.
Joaquín M López Muñoz wrote:
Check the docs for more info on each particular container
That is the one thing i hate about STL, the docs are completely useless.
/Magnus
|
|
|
|
|
I believe that this won't work. For the following reason: most implementations of map store items in sorted order so adding items
to the map will probably be between begin and end. Unless you are adding things that are bigger than what is in the map.
John
|
|
|
|
|
From the docs for map::insert
inserting an element invalidates no iterators, and
removing an element invalidates only those iterators
that point at the removed element.
If your AddToMap is adding to this map, you will get those elements back also. What are you really trying to accomplish here? It seems you want to double the size of the map, generating new keys and values based on the previous ones. I don't think I've ever seen such an algorithm before.
But to solve your problem you could create another map object that was a copy of this map and then add to the old map based on this new one. Like:
std::map<whatever> map2(map.begin(), map.end());<br />
iterator itBegin=map2.begin();<br />
iterator itEnd=map2.end();
use these iterators to insert stuff into the original map object.
It's probably not what you really want, but it should do what you explained you want.
|
|
|
|
|
Mike Nordell wrote:
What are you really trying to accomplish here? It seems you want to double the size of the map, generating new keys and values based on the previous ones. I don't think I've ever seen such an algorithm before.
Yes. This looked very strange to me. Also map will not allow you to enter the same key in the map more than once so I hope there is some translation..
John
|
|
|
|
|
How can I put my window transparently on desktop (just like Explorer does) using SysListView32 ?
|
|
|
|
|
I'm trying to use the Asobe SVG viewer with my CMultiPageDHtmlDialog based project. The problem is that if I put the activeX into one of the HTML pages, the aplication don't works. The HTML page in which is present the SVG viewer don't achieved the READY_STATE_COMPLETE state (so OnDocumentComplete is not called) and furthermore, I can't recieve any of the other ActiveX events.
I need Help. Thanks
Jose Vicente
|
|
|
|
|
HELP!
Tryting to perfrom a PCM to True Speech WAV conversion, find it really tough. There doesn't seem to much in the way of good sample code out there. Does anyone have any experience with this who can point me in the right direction?
Much Appreiated
Rich
|
|
|
|
|
Look around on the former Dialogic Corp's support website. There is some sample code there to do ADPCM to WAV, not exactly wat you want but a good starting point. PCM should be pretty much a sraight series of linear samples, so you just need to figure out what he proper WAV encoding is going to be. I'm not sure what this True Speech is, but a standard WAV file is usually stored as PCM. In that case there really is no conversion, just a file format change. Hope this helps some..
|
|
|
|
|
My program creates an object of CList, the nodes of which contains CMessage class object. The file has two functions, Write2List() and ReadFromList().After executing the program,i get no errors. But if i debug the program, i get "Unhandled Exception-0xC0000005:Access Violation" error after coming out of the ReadFromList(). Please help.
The code is as follows
include <memory.h>
#include <afxtempl.h>
#include <iostream.h>
class CMessage
{
public:
unsigned char m_cnt, m_mid;
public:
//constructor
CMessage();
CMessage(unsigned char nCnt, unsigned char nMid, unsigned char* pdata);
//destructor
~CMessage();
void SetValues(unsigned char nCnt, unsigned char nMid, unsigned char* pdata);
int GetData(unsigned char* pdata);
private:
unsigned char m_data[4]; //body of the message
};
CMessage::CMessage()
{
}
CMessage::CMessage(unsigned char nCnt, unsigned char nMid, unsigned char* pData)
: m_cnt(nCnt), m_mid(nMid)
{
for(int i=0; i <= ( m_cnt - 2); i++)
m_data[i] = *pData++;
}
CMessage::~CMessage()
{
// m_cnt = '\0';
// m_mid = '\0';
// memcpy(m_data,'\0',16);
}
void CMessage::SetValues(unsigned char nCnt, unsigned char nMid, unsigned char* pdata)
{
m_cnt = nCnt;
m_mid = nMid;
for(int i=0; i <= ( m_cnt - 2); i++)
m_data[i] = *pdata++;
}
int CMessage::GetData(unsigned char* pdata)
{
for(int i=0; i <= ( m_cnt - 2 ); i++)
*pdata++ = m_data[i];
return 0;
}//end of class CMessage
//typedef for our list template.
//Type is CMessage
CList<CMessage, CMessage&> myList;
void Write2List()//CMessage* pMessage1)
{
unsigned char data[4];
data[0] = 0x01;
data[1] = 0x02;
data[2] = 0x00;
data[3] = 0x04;
//first time of Initialisation
CMessage* pMessage = new CMessage();
//setting values thru the function.
pMessage->m_cnt = 0x40;
pMessage->m_mid = 0x30;
pMessage->SetValues(0x20,0x41,data);
myList.AddTail(*pMessage);
}
void ReadFromList()
{
unsigned char data[10], mCnt,mMid;
CMessage pMess;
while(myList.GetCount() != 1)
{
pMess = myList.GetAt(myList.GetHeadPosition());
mCnt = pMess.m_cnt;
mMid = pMess.m_mid;
pMess.GetData(data);
myList.RemoveHead();
}
cout<<"abc"<<endl;
cout<<(int)data[0]<<endl;
}
void main()
{
Write2List();
Write2List();
cout<<"ABC"<<endl;
ReadFromList();
cout<<"XYZ";
}
Roopa
|
|
|
|
|
pMessage->SetValues(0x20,0x41,data); This line in Write2List seems to indicate that data is 0x20-2=20 bytes long, yet it contains only 4 bytes. This might be causing the error.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thank u very much for ur help. Now it is working fine
Roopa
|
|
|
|
|
As an aside, it would make your life a lot easier if you use STL for your collection classes inside of the MFC collection junk.
|
|
|
|
|
Greetings all,
Can someone tell me if there is a way to watch the activity on a port with out issuing the 'listen' call.
I am building a small app (to run on windows) that listens on port 80, but I don't want to (can't) allow both the server and my app to 'listen' on the same port and I don't want to interfere with the servers performance. Can somone enlighten me on a way to do this.
|
|
|
|
|
You need to write a sniffer for that. Check the Platform SDK for some socket options which allow you to open a raw socket.
HTH
|
|
|
|
|
i encounter an problem: i need to Update one database on following conditions:
1. if the application is running at 0:0am in the morning ,it should update the database;
2.everyday the first time to start the application ,it should update the database;
3.everyday the database should be updated only once.
as far as i have thought about, i don't want to use the Task schedular ,also i am bored to handle WM_TIMER .
then can anybody tell me what to do by rule of thumb?
thanks in advance !
|
|
|
|
|
Hi everyone
I wonder if there is any embedded implementaion or helper class of Regular Expression in VC/C++? Or any third part surport?
I've heard that Regular Expression is used a lot by compliers. So can we use the complier as the embedded intepreter of Regular Expression? If we can, how?
Thank you. Waiting for your help.
|
|
|
|
|
there are libraries (i never used)
try search for regex, regexp++ etc. (see http://www.codeproject.com/string/re.asp or sourceforge.net)
t!
|
|
|
|
|
I've used the Regex classes in boost (www.boost.org) - they seem to work pretty well. There's also the Greta library from some guy @ Microsoft (go to research.microsoft.com & search for 'Greta')
Hope these help...
|
|
|
|
|
I've heard something to the effect that these two very implementations are the ones competing for a place in the C++0x library. As with all rumours one should take them with a grain of salt, but perhaps it could be something to plan for.
|
|
|
|
|
You can use Regular Expression with ATL 7. I forgot the name of the new classes
but go to MSDN, you can have more details.
One good thing about getting older, you don't lose the ages you've been!
|
|
|
|
|
Thank you all. These are really helpful.
But there is really a petty about using boost. When I've installed it, I find the RE implementaion relies on some DLL objects. That introduces the installation problem because I want to build a COM server that depends on nothing except using static linking.
Maybe I should try ATL 7, as Ernest suggested.
|
|
|
|
|
You can build the regular expression library in Boost as a static link library - Boost Regex should pick that if you're statically linking to the C run-time. To force use of the static library, put
#define BOOST_REGEX_STATIC_LINK
in your stdafx.h (or as a command-line argument to the compiler, whatever). It does work, believe me - I've been through all that (used it in a small WTL app. that I wanted to have minimal DLL dependencies...)
|
|
|
|
|
It provide DesktopColorizer.dsw demo From www.softshape.com , we can move the entire window in client , now I want to nomove the window , What can I do it ?
sai of china
|
|
|
|
|
Say I have a Bitmap resource IDB_BITMAP1
How do I draw this bitmap onto my CView ?
Regards
Nish
p.s. did some quick searches on CP. Saw some classes. I dont want any classes. Want some code pointers
Regards,
Nish
Native CPian.
Born and brought up on CP.
With the CP blood in him.
|
|
|
|