|
Many of the internet releated specifications are managed by the W3C organization[^]. You should probably begin by becoming familiar with the HTTP/1.1 standards[^]. Your probably not going to find a library specifically designed for web server string parsing.
Best Wishes,
-David Delaune
|
|
|
|
|
Hello guys,
I wanna make a map that contains an integer key and a struct as value type.
struct SRect
{
int iX, iY, iW, iH;
};
map<unsigned int=""> RectMap;
This piece of code compiles fine. However, if I want to insert a pair into the map a runtime error occurs.
void MakeParamRect(int iID, int iX, int iY, int iW, int iH)
{
RectMap[iID]->iX = iX;
RectMap[iID]->iY = iY;
RectMap[iID]->iW = iW;
RectMap[iID]->iH = iH;
}
I've also tried it using the insert() function.
RectMap.insert(make_pair(iID, {iX, iY, iW, iH}));
In this case the struct notation with the curly brackets seems to produce the error (compiler says that a semicolon is missing before the first {).
How can I make this code work, or is a struct not a valid value type for a map (it is valid in my opinion)?
Thanks for your help.
|
|
|
|
|
hello
i am not sure you can put a struct into a map.
if i were you i would change the struct into a class with a copy constructor
regards
|
|
|
|
|
You can't use aggregate syntax (that's the curly bracket stuff) anywhere except a struct/array variable initialiser. However, you certainly can put a struct in a map .
Try the code below - it declares and initialises an SRect variable which it then inserts into the map:
SRect sRect = {iX, iY, iW, iH};
RectMap.insert(make_pair(iID, sRect));
|
|
|
|
|
What is your map definition?
is it
map<int, SRect *> RectMap;
or
map<int, SRect> RectMap;
In the first case, you'll have to insert the structure variable into the map as below :
RectMap[0] = new SRect();
or
SRect s;
RectMap[0] = &s;
i.e. before accessing the variable from map, make sure you've inserted it.
And as you're saying RectMap.insert(make_pair(iID, {iX, iY, iW, iH})); gives compiler error, I'm pretty much sure that your map declaration is as :
std::map<int, SRect *> RectMap;
Better this will help you more...
|
|
|
|
|
I've few confusions.
It's possible to store structure as a value inside map.
std::map<int,srect> mymap;
Austrian_Programmer wrote: void MakeParamRect(int iID, int iX, int iY, int iW, int iH)
{
RectMap[iID]->iX = iX;
RectMap[iID]->iY = iY;
RectMap[iID]->iW = iW;
RectMap[iID]->iH = iH;
}
As per your code, you created the map as
std::map<int,srect*> mymap;
Probably you might be accessing an NULL or invalid pointer.
-Sarath.
"Great hopes make everything great possible" - Benjamin Franklin
|
|
|
|
|
I found out that if I just use the struct and not struct pointers as map value type it's working without making any problems. Anyway, I don't understand why.
In the meantime I also found a few code examples using a struct or a class as map value type, but I didn't see any examples using struct pointers.
|
|
|
|
|
I asked you regarding structure pointer as value because in the function you've mentioned using -> operator instead of . (dot) operator to access the members.
-Sarath.
"Great hopes make everything great possible" - Benjamin Franklin
|
|
|
|
|
map RectMap; <- error
typedef unsigned key_type; <- any type you want
std::map<key_type, SRect> RectMap; <- OK
SRect sr = {iX, iY, iW, iH}; <- should work
RectMap[iID] = sr;
OR
RectMap[iID] = {iX, iY, iW, iH}; <- should work
Only write something like RectMap[iID]->iX if you are storing pointers to type sRect in the map; which would be bad and stuped unless you have a really good reason for doing so.
If you are storing pointers ( std::map<key_type, SRect*> ) in the map, then you will need to write a method to free the memory pointed to by all those elements before you allow the map to be destroyed. If you are storing the actual data instead ( std::map<key_type, SRect> ), then the clean up will be automatic when the map is destroyed.
To recap:
... BAD ...
std::map<key_type, SRect*> RectMap; <- bad
RectMap[key] = new SRect(iX, iY, iW, iH); <- this is why it is bad
void cleanup_before_destruction() <- and this is why it is bad
{
std::map<key_type, SRect*>::iterator i;
for( i = RectMap.begin(); i != RectMap.end(); ++i )
delete *i;
}
... GOOD ...
std::map<key_type, SRect> RectMap; <- good
SRect sr(iX, iY, iW, iH);
RectMap[key] = sr;
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
Hi Friends
Please see the following code
<br />
wstring str1 = L"Test";<br />
wchar_t* buffer = new wchar_t[str1.length()+2];<br />
wcscpy(buffer, str1.c_str());<br />
Now here How much bytes extra I need to allocate for buffer for '\0' terminating character?
+2 or +1?
- Vikram S
|
|
|
|
|
You only need one extra element to hold '\0' because you're allocating with type wchar_t which is two bytes in size
-Sarath.
"Great hopes make everything great possible" - Benjamin Franklin
|
|
|
|
|
|
compiler will itself take care of sizeof NULL, you just have to allocate only 1 extra space to wchar_t
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
Hi,
I want to create a service which will launch a application which has GUI. I would like this application as a interactive with user. Is there any way by which I can create service.
Thanks
SNI
SNI
|
|
|
|
|
User the CreateProcessAsUser to launch such an application.
Service run in high privilege and so such apps must be launched with the security token of an interactive user.
In Vista interactive services are not allowed.
«_Superman_»
|
|
|
|
|
The CreateService documentation[^] mentions the SERVICE_INTERACTIVE_PROCESS flag for the dwServiceType flag, which seems applicable?
There's also this page[^], which talks about interactive services?
Does that help?
|
|
|
|
|
Thanks for your reply. But I tried with this but due to this there is a problem in service start up.
SNI
|
|
|
|
|
Vista is explicitly disallowing interactive services nowadays - they strongly encourage some sort of IPC between the service and a client user program.
Iain.
|
|
|
|
|
Sounds fair enough, to be honest. I'm not using Vista anywhere, so haven't fallen over that (yet).
If it was a WinXP/Win2000 compatibility problem, however, I'd be all over it - the standard desktop OS where I work is still Win2000....
|
|
|
|
|
I only use Vista at home so I can keep my experience up. Work is all XP/2K.
But I try and keep an eye on (eg) Vista so I don't end up making a pain for myself in the future. I'm actually a bit of a fan of UAC - the only problem with it is that so much software is written arrogantly, assuming it has the right to piddle all over my machine.
[rant]
You (not necessary Mr Dootson) have sold me a game. What possible justification can you give to get me to give you admin rights? It's handy for you? Tough, write better code.
[/rant]
At least games have a selfish excuse of installing DRM. It may not be a /good/ excude, but it's plausible. But the amount of 'real' apps that misbehave...
Yours respecting the difference between HKLM and HKCU since 1999...
Iain.
|
|
|
|
|
Iain Clarke wrote: the only problem with it is that so much software is written arrogantly, assuming it has the right to piddle all over my machine
Couldn't agree more - that's why I've always (since we started using Windows 2000) been an advocate of doing all development work (or testing, at very least) as a non-privileged user, rather than as admin. That's the only way I can be reasonably sure that I've implemented solutions that are appropriate for the environment in which they're to be deployed - or alternatively be able to identify exactly where you have to step outside the security limitations.
|
|
|
|
|
I do test under a limited user, but I don't develop that way - too much of a pain. But if my code breaks my machine, at least it's my own fault...
Quite a lot of my work is interfacing with other peoples hardware libraries, so opening up the odd security hole for them can be a bit painful for my principles.
Iain.
|
|
|
|
|
Iain Clarke wrote: [rant]
You (not necessary Mr Dootson) have sold me a game. What possible justification can you give to get me to give you admin rights? It's handy for you? Tough, write better code.
[/rant]
[counter-rant]
You have bought, if have you (not necessary Mr Clarke ), the game. Now, how can that game meet all your expectations about its performances without hacking your machine? So, please, first make it admin and then bomb Los Angeles!
[/counter-rant]
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
CPallini wrote: So, please, first make it admin and then bomb Los Angeles!
While I do have a powerful machine at home, I have yet to connect my USB powered stealth bomber... (cordless, of course...)
Would a USB xmas tree do the job? Or nerf missiles? I can borrow then...
Iain.
|
|
|
|
|
Iain Clarke wrote: Would a USB xmas tree do the job? Or nerf missiles? I can borrow then...
Have you a USB xmas tree ?
I shoud know you have it: UK is far more advanced than Italy ...
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|