storing contents in vectors in C++ language [closed] - c++

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
How do you store contents in a vector and then sort them without creating a class?
Doing a class project and it requires to not use a class. The books are not helping.

This page has a good example, assuming you can put all of the elements in the vector at once. If you need to put them in one at a time, use std::vector::push_back.

Something like std::vector<std::string> v; v.push_back("hello"); std::sort(v.begin(), v.end());. Get better books.

Related

How to create an empty std::map object? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I tried this:
std::map<int,int> m;
and it works -- m becomes an empty map. But this approach may not work if the compiler choose to not initialize m to an empty map by default. Better solution?
Any better solution?
Taking your question literally, no. There is no better solution.
This will create a default constructed, and therefore empty std::map<int,int>.
std::map<int,int> m;

Calling keys in C++ for their values [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Hi I need to type a code which calls the key and its values such as "Tokyo 10 23 32". I can't use arrays or vectors how can I store my data? Thanks.
Use std::map or std::unordered_map. std::map uses a Red-Black tree, and std::unordered_map uses a Hash Table.

Can you have a string and a integer in one vector? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I just have a general question. Can you have a string and an integer in one vector? I am planning to display card names and numbers. I want to display both and wanting the numbers to be added up at the end. Can I do this?
You can have std::string and int in one std::vectorusing std::variant
using ElementType = std::variant<std::string, int>;
std::vector<ElementType> v;
v.push_back(std::string("I am string"));
v.push_back(1);

Finding indexed data-structure like `std::vector` (not array) [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I am looking for a data structure which can store values with index and also can be resized like a std::vector (but should be indexed so I can access it easily) is there any C++ standard library implementation of my problem?
What I am looking for is an array-type DS from which I can remove elements.
You can use std::deque which is also indexed sequence container like std::vector. It provids also std::deque::resize member function.
However, your requirement should be much more specific to suggest std::deque at first place than std::vector

How to sort a pair of keys and values using boost? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
Is there some function in boost library which can sort key-value pairs?
e.g. keys being an array of double variables, and values are some index (integer) of the array.
What you probably want is a std::map<My_Double_Array, size_t> along with your own My_Double_Array class that wraps your array of double variables and provides a operator <() for sorting. Or simply std::map<std::vector<double>, size_t> might be all you need.