How I can determine the size of string array?

Hi every one...

I have the prototype

std::vector<std::string> to_vector( std::string[] words );

I need to determine the size of words...

How to do it?
that doesn't compile.
Thanks for reply....
Can't I do it?
Do I need the size of the array?
You can use std::array and use std::array::size();
You need to pass the size of the array as a second parameter. This is idiomatic in C.
 
std::vector <std::string> to_vector (std::string * words, std::size_t sz);

Expressions evaluating to arrays decay to pointers when passed to functions. Pointers don't contain size information, but arrays do. This is why the array parameter syntax is awful (because it's a lie) and you should just use a pointer instead.

You can also pass a reference to an array of size N where N is a non-type template parameter:
 
template <std:: size_t N> std::vector <std::string> to_vector (std::string (& words) [N]); 


But that has some drawbacks. Better yet just lose the C-style array entirely.
Thanks for your reply...
Topic archived. No new replies allowed.