I tried this declaration of array and check the size:
string path1[1] = {"D:\\Users\\user-pc\\Desktop\\testing\\inputs\\xml_source_example.xml"};
cout << path1->length();
and checked the size:
62
I wanted the output to be 1, so I tried with ->size() and I still got 62. I know that the first item in the array has length of 62, but I want the number of items in the array.
How can I get how many items there are in the array?
Try this, leveraging std::begin
and std::end
:
std::end(path1) - std::begin(path1);
Alternatively, you can role out your own array size function:
#include <cstddef> // for std::size_t
template <typename T, std::size_t N>
constexpr std::size_t size(const T(&)[N])
{
return N;
}
Usage:
#include <iostream>
int main()
{
int a[42];
std::cout << size(a) << std::endl;
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments