QVector > startsWith

QVectorの先頭・末尾が指定した要素か確認

解説

startsWith()はQVectorの先頭が指定値と一致するかどうかを確認します.
endsWith()はQVectorの末尾が指定値と一致するかどうかを確認します.

定義は以下の通りです.
bool QVector::startsWith ( const T & value ) const
bool QVector::endsWith ( const T & value ) const
引数valueには確認対象の値を指定します.要素が一致した場合はtrueを,それ以外はfalseを返します.

使用例

  1. #include <QTextCodec>
  2. #include <QTextStream>
  3. #include <QVector>
  4. int main(int argc, char *argv[]) {
  5. QTextCodec::setCodecForTr(QTextCodec::codecForLocale());
  6. QTextStream out(stdout);
  7.  
  8. QVector<QString> vec;
  9. vec << "a" << "b" << "c" << "d" << "e";
  10. out << vec.startsWith("a") << "\n";
  11. out << vec.startsWith("A") << "\n";
  12. out << vec.endsWith("e") << "\n";
  13. out << vec.endsWith("E") << "\n";
  14. return 0;
  15. }

出力
1
0
1
0
最終更新:2011年09月24日 05:04
ツールボックス

下から選んでください:

新しいページを作成する
ヘルプ / FAQ もご覧ください。