Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
配列があるとしましょう:
string w[10];
そして私は声明を持っています:
if(w.size() > 10) { // How would I print out the 11th character? char a = w[11]; cout << a << endl; }
11番目の文字をどのように印刷しますか?キャラクターaに保存してみましたが、何も印刷されていないようです。
なぜ配列の境界の外に印刷したいのですか?配列のサイズを超える文字を印刷することは未定義であり、クラッシュを引き起こす可能性があります。
また、w[11]は実際には12番目の要素です。配列は0に基づいているため、11番目の要素はw[10]です。
実際に配列のサイズを動的に設定しますか?文字列を使用しようとしている場合は、おそらくstl文字列が必要なのでしょうか。それはヘッダーで定義され、<string>経由で使用されます
<string>
std::string somestring("string you want");