can anyone help me convert this to c++??
<?php
function show_me($info) {
$arr = array('fruit' => 'apple', 'car' => 'bmw');
return $arr[$info];
}
echo show_me('fruit');
//or echo show_me('car')
?>
can anyone help me convert this to c++??
<?php
function show_me($info) {
$arr = array('fruit' => 'apple', 'car' => 'bmw');
return $arr[$info];
}
echo show_me('fruit');
//or echo show_me('car')
?>
std::map <std::string, std::string> array;
array["fruit"] = "apple";
Thanks!!!!
ok, now how can i put all that array in a new array?
so that i can have more then 1 array["fruit"] = "apple";
??
to be array["fruit"] = apple;
array["fruit"] = strawberry;
array["car"] = bmw;
array["car"] = audi;
please help :(
std::map <std::string, std::vector<std::string> > array;
array["fruit"].push_back( "apple" );
array["fruit"].push_back( "pear" );
The STL has a whole set of goodies like this - http://www.sgi.com/tech/stl/
really thanks for your big help, can i vote you somewhere or something like this?
sorry for disturbing;
i have another question
i want to make a function len()
so can return the size of a vector
how can i make
int len( vector< any_type_of_vector(int,string....) array) {
return (int)array.size();
}
thanks for your time
Why would you want to make a function for that, when the size() function already exists?
Here's a code example of size() using Salem's demo-code:
std::map <std::string, std::vector<std::string> > array;
array["fruit"].push_back( "apple" );
array["fruit"].push_back( "pear" );
cout << "The map 'array' has " << array.size() << " vector(s)\n";
cout << "The vector 'fruit' in map 'array' has "
<< array["fruit"].size() << " elements\n";
thanks for the help, found in the end something;
well i need a function like that because i am using multiple types if arrays including array[] so to type everytime sizeof(array)/sizeof(int) takes more time then i desire, and know my code reached 2000 lines, and is not even done yet, hard to write every type of array.size()
so i made this:
template <typename T>
int len(vector< T > array) {
return (int)array.size();
}
int len(int *array) {
int size = sizeof(array)/sizeof(int);
return size;
}
wich helps me a lot for doing:
for(int i=0; i<len(array); i++) {
}
nice, isn't it?
tanks once again
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.