memcpy
std::string content;
size_t fileSize = static_cast<size_t>(file.tellg());
file.seekg(0, std::ios::beg);
if (fileSize)
{
buff = new char[fileSize];
file.read(buff, fileSize);
content.resize(fileSize);
// 快速将 buff 中的数据复制到 content 中
memcpy(&content[0], buff, fileSize);
delete[] buff;
}
strcpy
const char* charData = "Hello, World!";
std::string strData;
strData.resize(strlen(charData)); // 调整std::string大小以容纳数据
strcpy(&strData[0], charData); // 使用strcpy复制数据