|
You can still use iterators
std::vector<S>::iterator it;
for(it = Vec.begin(); it != Vec.end(); it++)
{
cout << "Before: "<< it->a << " : " << it->str.c_str() << endl;
it->str = "New string value";
cout << "After: "<< it->a << " : " << it->str.c_str() << endl;
}
The iterator can be thought of as a pointer to your elements. There is no need to use indexing syntax just to update your data.
|
|
|
|
|
Thanks, thats correct. I am just still thinking in C
011011010110000101100011011010000110100101101110
0110010101110011
|
|
|
|
|
Hi,
If the interger values are going to be unique then you can go for,
std::map<int, struct S>
Do your Duty and Don't expect the Result
|
|
|
|
|
Thanks, i'll check this one out
011011010110000101100011011010000110100101101110
0110010101110011
|
|
|
|
|
As an aside, you don't need a typedef with every struct definition - you can use the 'tag' of the struct in the same way you can use a class name.
Two options:
1. If you really only have an int that serves as soem sort of unique ID, and some value associated to that ID, then you should use a map rather than a vector. std::map automatically sorts your elements by your key values when you insert them. Retrieving an item is a simple and very fast operation.
2. If there's more to it, you can still use the std::find() method to locate a specific struct in your vector. You only need to define an equality operator for your struct like this: (not tested)
#include <vector>
#include <algorithm>
struct S {
int a;
std::string b;
bool operator==(const S& s) const {
return s.a==a;
}
S(int a_) : a(a_) {}
S(int a_, std::string b_) : a(a_), b(b_) {}
}
int main() {
std::vector<S> s;
s.push_back(S(1, "hi"));
s.push_back(S(10, "hello"));
std::vector<S>::iterator location = std::find(s.begin(), s.end(), 5);
std::string result;
if (location != s.end();
result = location->b;
}
You can check the online documentation on std::find() and std::find_if() for examples.
P.S.: anyone knows what is messing with code coloring here?
modified on Friday, April 8, 2011 2:40 AM
|
|
|
|
|
Hey thanks! This gave me some ideas
P.s. i know that i dont need typedefs for structs
btw. i had some time ago same issue with coloring thing - that is because you haven't probably replace html tags (<>)
011011010110000101100011011010000110100101101110
0110010101110011
|
|
|
|
|
Glad to be of help.
csrss wrote: you haven't probably replace html tags
Good call! After replacing the < and > in the #include lines it worked. It's strange though, inside the actual code this wasn't neccesary.
|
|
|
|
|
Hi,
How can i create Setup file in 'Visual Studio 6.0'
I have used “ Package and Deployment Wizard “ of 'Visual Studio 6.0' for this purpose.But its searching for .vbp file.
Actually my file is developed in 'Visual Studio 6.0' . So can you please guide me any way to create setup file.
Thanks in advance
|
|
|
|
|
|
I agree wholeheartedly with Hans. The site
http://www.jrsoftware.org
has an excellent and free program called Inno Setup.
|
|
|
|
|
is that free for home users or is it free for commercial users as well?
|
|
|
|
|
I believe it's free for everyone, although you can donate if you want.
[update] From the Inno Setup site:
Is it really free of charge, even for commercial use?
Yes, it may be used completely free of charge, even when deploying commercial applications. However if you wish to show your appreciation and support its development you can make a donation. [/update]
|
|
|
|
|
I definitely have to check it out then!
|
|
|
|
|
I used inno setup for a solid 14 months, and I've churned out great installers that are easy to create and yet highly capable. I strongly recommend that you check it out!
"Real men drive manual transmission" - Rajesh.
|
|
|
|
|
I use InstallShield... and its easy to use, but for that price... I'd expect A LOT more (since its freakin' expensive!)...
|
|
|
|
|
Albert Holguin wrote: I use InstallShield... and its easy to use Wow! I don't think I've ever heard anyone say that before.
|
|
|
|
|
Really? it is... not much to it... but I hate certain things about it... don't know if they've fixed it since, but in my version, all file links were static!!! why!?!?! so you end up having to put the files in the same EXACT directory structure as they were originally in! very annoying!
|
|
|
|
|
...although i should clarify... it wasn't easy off the back, there was a learning curve, but once you figure it out, its pretty easy to work with and remember
|
|
|
|
|
|
I had to learn it... its what they were using at work ...but at this point, i can change what i don't like
...its what i've earned for lack of a life...
|
|
|
|
|
Hi all,
CFormView::OnClose() ( WM_CLOSE ) event is not coming.
Can u tell me the reason?
|
|
|
|
|
CFormView::OnClose() is not called because views do not have a close button. The close button belongs to the frame window, and OnClose() is a message handler for it.
You could call something in the view from your frame window OnClose() , or add a message handler in the view for WM_DESTROY (OnDestroy() ).
|
|
|
|
|
yes thank you.
I have to call OnClose() of View's frame.
|
|
|
|
|
Can any one tell me that how to use visual leak detector.???
I am using visual studio 2003.
Thank u in advance.
|
|
|
|
|