查看以下功能:C++使用和引用返回
std::string& foo (std::string& s)
{
s.erase(0.s.find_first_not_of(" \f\t\v\r\n");
return s;
}
当一个人在一个字符串传递,它确实修改原始字符串吧?为什么要在修改原始文件时返回修改过的字符串?
试图更好地理解为什么有人可能用这种方式编码此功能?那么有人这样做,所以我被问到为什么我只做以下几点:
std::string mystring = " This is cool";
foo(mystring);
std::cout << mystring << std::endl;
为什么我没有使用返回的值?