Posted March 4, 2013 Hey guys! I've written a C++ console application to carry out series of mathematical calculations for my university course. In this I have used vectors to store and call values depending on the set selected. I'm now trying to create a GUI for this program using a Windows Form Application. It's been going well up to the point where I tried to use vectors. I did some digging online and found that I can use 'List' as a alternative. I can change out the 'push_back' function for the 'Add' function associated with Lists but I'm a bit confused about how to call the values again. When I used vecors, the command to call the value from a vector was "vectorname.at(position in vector)". Can anyone tell me the equivalent function relating to Lists?? Cheers for reading! Link to comment Share on other sites More sharing options... Link to post Share on other sites More sharing options...
Posted March 4, 2013 Yea you can use generic List ( List ). You can use vectorname.ElementAtOrDefault(index); You can also use Find with a delegate function if you want to return a value that matches a specific criteria. For example : private static List vectorname = new List(); myObject result = vectorname.Find( delegate(myObject mo) { return mo.value == valuetoFind; } ); Link to comment Share on other sites More sharing options... Link to post Share on other sites More sharing options...
Posted March 4, 2013 From the C++ console application I've just made up to test lists and vectors I have 2 suggestions: 1. I haven't made many gui apps in c++ but I would stick with vectors because you can access them as easily as vectorname[position]; 2. You could use an iterator with lists. From what I could find about it you can do list::iterator it = std::next(list.begin(), 3); myObj object = *it; //You could do this in the same line (As seen in http://stackoverflow.com/questions/5733842/how-to-get-a-certain-element-in-a-list-given-the-position) Link to comment Share on other sites More sharing options... Link to post Share on other sites More sharing options...
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now