Again problems with an array of std::string

I dont know if the best I can to do is to use vector <std::string> instead of array.
I have a fast method to pass some std::string values to a function

1
2
3
  std::string data[]="{"one","two","three"}
  .....
  Myfunction (std::string the_data[]){} 


My questions :
I'm unable to obtain the number of elements of the_data
Any help ?


the_data is just a std::string*. It doesn't know how long it is. You'll have to pass the length separately or use a vector. This is true for any kind ow array.

const unsigned n_data = sizeof( data ) / sizeof( data[0] );
@kfmfe, he was asking about the function argument..
And even for normal array, this isn't great, as it doesn't check that this is an array at all.
1
2
template<typename T, int N>
int get_size( T (&t)[N] ){ return N; }
Is better.
nice technique - thx!
Thanks to everybody
hamsterman - this should only work with fixed length arrays right? This feels kind of obvious, still I kinda feel like asking cause I might have missed something (I mean, template instantiation is at compile time, so there is no way this could work with dynamic arrays?).
of course.
Oh ok, sometimes I just feel silly like that.
Topic archived. No new replies allowed.