C++中的String的常用函数用法总结: https://blog.csdn.net/qq_37941471/article/details/82107077
1,将构造的对象初始化为s的前n个字符,s不够n个时将相邻的内存单元的内容当作s的一部分继续复制:
string(const char *s, size_type n, const Allocator &a = Allocator());
std::string testStr("Telephone home.", 4);
OutputDebugStringA(testStr.c_str());
// 输出:Tele
2,将构造的对象初始化为s的后n个字符,也就是从s指向的内存的第n个字节开始复制:
string(const string &str, size_type pos,size_type n = npos, const Allocator &a = Allocator());
std::string text("Telephone home.");
std::string testStr(text, 4);
OutputDebugStringA(testStr.c_str());
// 输出:phone home.
string(size_type n, char c, const Allocator &a = Allocator()) std::string testStr(10, 'a');
OutputDebugStringA(testStr.c_str());
// 输出:aaaaaaaaaa