I have a query in T-SQL which returns 300 records. Each record has 2 columns (date, int)
What is the easiest way in C++ to put all the dates in one vector and all the integers in another one?
I would like to do it in a function.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It’s hard to provide full code without knowing your SQL client library – this affects how you populate the
vectors, but basically you loop through the rows read from the DB doingpush_backon your twovectors for the values retrieved in each row.The main question is how are you going to handle the returned parameters? You have two
vectors, as you have specified the problem here. You could achieve this by having the caller create thevectors and then the function populate them, like this:For extra credit because of better encapsulation or the row data, I would be inclined to use a vector of POD structures. The advantage of this is that each date and value then remain tightly coupled – you can extend this into a full-blown class if you have operations you wish to do for each row. Hide the data behind getters, preferably.