掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
char s[10][10]をstd::sortでソート (ID:70365)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
2次元配列 char tab[10][10] をstd::sortでソートしたいのですが、 std::sortへの引数の渡し方がわかりません。 どのように書いたらよいでしょうか? #include <algorithm> #include <cstdio> #include <cstring> #include <iostream> using namespace std; bool cmp_strcmp(const char* a, const char* b) { return strcmp(a, b) < 0; } int main() { char tab[10][10]; int n = 0; strcpy(&tab[n++][0], "ab"); strcpy(&tab[n++][0], "hello"); strcpy(&tab[n++][0], "abd"); // sortでソートしたい // sort(??, ??, cmp_strcmp) // ??の部分がわかりません // 出力 for (int i = 0; i < n; i++) puts(tab[i]); } 期待する実行結果: ab abd hello
←解決時は質問者本人がここをチェックしてください。
戻る
掲示板システム
Copyright 2020 Takeshi Okamoto All Rights Reserved.