部分文字列の c-string の配列を検索する必要があります。
答えが返ってくると思ったものを作成しましたが、構文的に正しいだけで意味的に間違っていますが、どこが間違っているのかわかりません。
これにはサブクエスチョンもあります。私が試した例を示した後、質問します。
#include <boost/algorithm/string/find.hpp>
const char Months[12][20] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
void Test()
{
typedef boost::iterator_range<boost::range_iterator<const char [20]>::type > constCharRange;
boost::iterator_range<char const *> ir = find_first("January", months);
}
ir.first == ir.last
イテレータの結果は、これを正しく記述していないことを示しています。
最初のパラメーターが実際にconst char [8]
悪影響を及ぼしているかどうかはわかりません。
私の主な質問は、それを修正するために何をすべきか、そして補足的な質問は、constCharRange または実際にそのような typedef から find_first が必要とする型をどのように抽出できるかです。
編集:
end を間違って使用していることがわかります。その後、わずかに異なる例を機能させることができましたが、実際に使用する必要がある定義と互換性がありません (コードに追加することはできますが、既存の定義を変更することはできません)。
const std::string Months[]= { /*same data as before*/
void StringTest2()
{
const std::string* sptr =0;
sptr = std::find(boost::begin(Months), boost::end(Months), std::string("February"));
if (sptr)
{
string sResult(*sptr);
}
}
別のテスト
const char* Months[]= { /*same data as before*/
void StringTest3()
{
const char **sptr = std::find(boost::begin(Months), boost::end(Months), "February");
if (sptr)
{
string sResult(*sptr);
}
}
これは私が得ることができる最も近いものですが、戻り値の型の仕様を正しく取得できないようです
void StringTest4()
{
const char Months[12][20]Months[]= { /*same data as before*/
std::find(boost::begin(Months), boost::end(Months), "February");
}