目次 |
---|
・C++のString |
#include <iostream> #include <string > int main{ string str1; str1 = "abc"; std::cout << str << std::endl; return 0; }str1はコンストラクタなしのため、空文字列で初期化されます。stringは内部で自動的にメモリ確保されるため、文字数指定は不要です。
#include <iostream> #include <string > int main{ string str1,str2;//こんな宣言が可能 str1 = "abc"; str2 = "def"; str1 += str2;//文字列を連結 std::cout << str1 << std::endl; return 0; }