3

私は、テキスト ファイル (ボード) の行を読み取るBoggleゲーム ソルバーに取り組んでいます。

vectors の aを使用するstringか、s のvector行列を使用するかを行ったり来たりしていcharます。vectorofが関数を使用する必要がある場所であるため、ofのchars方がアクセスしやすいと思います。myvec[y][x]vectorstringstring.at()

char各行をs に解析するか、行を のままにして必要に応じstringてそれぞれにアクセスする必要がある場合、どちらがパフォーマンスが向上するかわかりませんchar。どちらをすべきかについての提案はありますか? 理由を説明すると役立ちます。

4

1 に答える 1

4

As commented, you can use operator[] on strings just like vectors or arrays.

Under proper optimisation, the performace will be about the same for vector<char> as for string - both are arrays under the hood, and in both cases operator[] will effectively be a structure member access and an indirect lookup. They even provide almost the same set of methods.

Choose whichever makes your code more readable/simple.

于 2012-05-08T01:56:34.237 に答える