标签:单位 xxxxxx string类 输出 seq int 返回 string 就是
初始化
size()、length()
1 //() 可以换成 { },都一样 2 int main () { 3 std::string s0 ("initial string"); 4 std::string s1; 5 std::string s2 (s0); 6 std::string s3 (s0, 8, 3); //从s0的第八个字符开始,长度是3 7 std::string s4 ("A character sequence", 6); //截取前六个字符来初始化s4 8 std::string s5 ("Another character sequence"); 9 std::string s6a (10, ‘x‘);//10个字符x 10 std::string s6b (10, 42);//10个字符*,因为x对应的asic码是42 11 std::string s7 (s0.begin(), s0.begin()+7);//s0的前7个字符,第二个参数要么是end,要么就是从begin开始加上长度 12 std::cout << "s1: " << s1 << "\ns2: " << s2 << "\ns3: " << s3; 13 std::cout << "\ns4: " << s4 << "\ns5: " << s5 << "\ns6a: " << s6a; 14 std::cout << "\ns6b: " << s6b << "\ns7: " << s7 << ‘\n‘; 15 return 0; 16 } 17 输出: 18 s1: 19 s2: initial string 20 s3: str 21 s4: A char 22 s5: Another character sequence 23 s6a: xxxxxxxxxx 24 s6b: ********** 25 s7: initial
返回字符串长度:str.size() == str.length(); 单位是bytes
标签:单位 xxxxxx string类 输出 seq int 返回 string 就是
原文地址:https://www.cnblogs.com/pacino12134/p/11025238.html