| | |
please help
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
C++ Syntax (Toggle Plain Text)
std::map <std::string, std::vector<std::string> > array; array["fruit"].push_back( "apple" ); array["fruit"].push_back( "pear" );
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
thanks for your time
i have another question
i want to make a function len()
so can return the size of a vector
how can i make
C++ Syntax (Toggle Plain Text)
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:
Here's a code example of size() using Salem's demo-code:
cpp Syntax (Toggle Plain Text)
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";
Last edited by niek_e; May 15th, 2008 at 3:52 am.
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:
wich helps me a lot for doing:
nice, isn't it?
tanks once again
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:
C++ Syntax (Toggle Plain Text)
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:
C++ Syntax (Toggle Plain Text)
for(int i=0; i<len(array); i++) { }
nice, isn't it?
tanks once again
Last edited by som3on3; May 15th, 2008 at 1:50 pm.
![]() |
Other Threads in the C++ Forum
- Previous Thread: Clarification in Classes
- Next Thread: help needed
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion convert count data delete deploy dll dynamiccharacterarray email encryption error file format forms fstream function functions game givemetehcodez graph gui homeworkhelp iamthwee ifstream input int java lib library lines list loop looping loops map math matrix memory newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg search simple sorting spoonfeeding string strings struct temperature template templates text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






