BYDFi
Trade wherever you are!
Buy Crypto
Markets
Trade
Derivatives
Bots
Events
common-tag-new-0
Rewardsanniversary-header-ann-img

How can I declare a vector in C++ for storing cryptocurrency prices?

Tesfalem TamenewelduMay 01, 2022 · 3 years ago1 answers

I am working on a project that involves storing cryptocurrency prices in a vector using C++. Can someone please guide me on how to declare a vector in C++ for this purpose? I want to make sure that I can easily access and manipulate the cryptocurrency prices in the vector.

1 answers

  • May 01, 2022 · 3 years ago
    Sure! Here's how you can declare a vector in C++ for storing cryptocurrency prices: ```cpp #include <vector> int main() { std::vector<double> prices; // Add cryptocurrency prices to the vector prices.push_back(100.50); prices.push_back(200.75); prices.push_back(150.25); // Access and manipulate the prices for (int i = 0; i < prices.size(); i++) { double price = prices[i]; // Do something with the price } return 0; } ``` This code declares a vector named 'prices' of type 'double' to store cryptocurrency prices. You can add prices to the vector using the `push_back()` function and access them using the subscript operator `[]` within a loop.