please help

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Apr 2008
Posts: 7
Reputation: som3on3 is an unknown quantity at this point 
Solved Threads: 0
som3on3's Avatar
som3on3 som3on3 is offline Offline
Newbie Poster

please help

 
0
  #1
Apr 17th, 2008
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')
?>
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 751
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: please help

 
0
  #2
Apr 17th, 2008
  1. std::map <std::string, std::string> array;
  2. array["fruit"] = "apple";
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 7
Reputation: som3on3 is an unknown quantity at this point 
Solved Threads: 0
som3on3's Avatar
som3on3 som3on3 is offline Offline
Newbie Poster

Re: please help

 
0
  #3
Apr 17th, 2008
Thanks!!!!
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 7
Reputation: som3on3 is an unknown quantity at this point 
Solved Threads: 0
som3on3's Avatar
som3on3 som3on3 is offline Offline
Newbie Poster

Re: please help

 
0
  #4
Apr 24th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 751
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: please help

 
0
  #5
Apr 24th, 2008
  1. std::map <std::string, std::vector<std::string> > array;
  2. array["fruit"].push_back( "apple" );
  3. array["fruit"].push_back( "pear" );
The STL has a whole set of goodies like this - http://www.sgi.com/tech/stl/
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 7
Reputation: som3on3 is an unknown quantity at this point 
Solved Threads: 0
som3on3's Avatar
som3on3 som3on3 is offline Offline
Newbie Poster

Re: please help

 
1
  #6
Apr 24th, 2008
really thanks for your big help, can i vote you somewhere or something like this?
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 7
Reputation: som3on3 is an unknown quantity at this point 
Solved Threads: 0
som3on3's Avatar
som3on3 som3on3 is offline Offline
Newbie Poster

Re: please help

 
0
  #7
May 14th, 2008
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
  1.  
  2. int len( vector< any_type_of_vector(int,string....) array) {
  3. return (int)array.size();
  4. }

thanks for your time
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,971
Reputation: niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute 
Solved Threads: 308
Moderator
Featured Poster
niek_e's Avatar
niek_e niek_e is offline Offline
Cenosillicaphobiac

Re: please help

 
0
  #8
May 15th, 2008
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:
  1. std::map <std::string, std::vector<std::string> > array;
  2. array["fruit"].push_back( "apple" );
  3. array["fruit"].push_back( "pear" );
  4.  
  5. cout << "The map 'array' has " << array.size() << " vector(s)\n";
  6. cout << "The vector 'fruit' in map 'array' has "
  7. << array["fruit"].size() << " elements\n";
Last edited by niek_e; May 15th, 2008 at 3:52 am.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 7
Reputation: som3on3 is an unknown quantity at this point 
Solved Threads: 0
som3on3's Avatar
som3on3 som3on3 is offline Offline
Newbie Poster

Re: please help

 
0
  #9
May 15th, 2008
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:
  1. template <typename T>
  2. int len(vector< T > array) {
  3. return (int)array.size();
  4. }
  5.  
  6. int len(int *array) {
  7. int size = sizeof(array)/sizeof(int);
  8. return size;
  9. }

wich helps me a lot for doing:
  1. for(int i=0; i<len(array); i++) {
  2.  
  3. }

nice, isn't it?
tanks once again
Last edited by som3on3; May 15th, 2008 at 1:50 pm.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC