Output a string thats assigned to an element in a double Array in C++ -


hey have pretty simple question answered. assigned elements of array string values. want code output string instead of element value. here example:

double stock[5] = {249.99,49.99,13.99,449.99,59.99}; double beats = stock[0]; double ipod = stock[1]; std::cout << "okay, purchased " << stock[0] << endl;

the output "okay, purchased beats." . output recieve "okay, purchased 249.99."

how can make print string instead of value? thank in advance.

you'll want kind of container, struct, class or pair. here's example (using pair):

#include <utility> #include <string>  ...  std::pair <std::string,double> stock [5]; stock[0]=std::make_pair("beats",249.99);  ...  std::cout << "okay, purchased " << stock[0].first << "." << endl; 

this output want ("okay, purchased beats.").

you can use stock[i].first access first element (the name, string), , stock[i].second access second element (the value, double).


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -