String型文字列の一文字目だけを取り出すにはどうすればいいのでしょうか?
気になる質問をクリップする
クリップした質問は、後からいつでもMYページで確認できます。
またクリップした質問に回答があった際、通知やメールを受け取ることができます。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。

回答2件
0
C++
1#include <iostream> 2#include <string> 3using namespace std ; 4 5 6int main( ) { 7 string str("Perfect number") ; 8 9 cout << str[0] << endl; 10 cout << str.at(0) << endl; 11 cout << *str.begin() << endl; 12 cout << *begin(str) << endl; 13 cout << str.front() << endl; 14 cout << str.c_str()[0] << endl; 15 cout << *str.c_str() << endl; 16 cout << str.data()[0] << endl; 17 cout << *str.data() << endl; 18 char c; str.copy(&c,1); 19 cout << c << endl; 20}
お好きなものを使いなされ。
投稿2018/07/23 23:01
編集2018/07/24 12:34総合スコア16612
0
これでしょうか?
c++
1usr~/test/cpp % cat tcp.cpp 2#include <iostream> 3#include <string> 4using namespace std ; 5 6 7int main( ) { 8 string str("Perfect number") ; 9 10 cout << str[0] << endl; 11 12 return 0 ; 13} 14 15usr~/test/cpp % ./a.out 16P 17usr~/test/cpp %
投稿2018/07/23 13:13
総合スコア6851
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
あなたの回答
tips
太字
斜体
打ち消し線
見出し
引用テキストの挿入
コードの挿入
リンクの挿入
リストの挿入
番号リストの挿入
表の挿入
水平線の挿入
プレビュー
質問の解決につながる回答をしましょう。 サンプルコードなど、より具体的な説明があると質問者の理解の助けになります。 また、読む側のことを考えた、分かりやすい文章を心がけましょう。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/07/24 08:28
2018/07/24 09:09 編集
2018/07/24 09:18
2018/07/24 09:27