There are multiple answers based on what you are doing with the string.
1) Using the string as an id (will not be modified). Passing it in by const reference is probably the best idea here: (std::string const&)
2) Modifying the string but not wanting the caller to see that change. Passing it in by value is preferable: (std::string)
3) Modifying the string but wanting the caller to see that change. Passing it in by reference is preferable: (std::string &)
4) Sending the string into the function and the caller of the function will never use the string again. Using move semantics might be an option (std::string &&)
相关文章
- 解决C++遇到的未定义标识符 “string“、未定义标识符 “cout“、“name”: 未知重写说明符错误
- Windows VS2022 C/C++ Console程序使用UTF8编码支持中文需要设置的6个地方
- C++的string类常见用法
- iOS开发中的错误整理,启动图片设置了没有效果;单独创建xib需要注意的事项;图片取消系统渲染的快捷方式
- Shared_from_this 几个值得注意的地方
- javascript——js string 转 int 注意的问题——parseInt
- C++实现CString和string的互相转换
- C++中 string对象的大小比较
- python 类属性 、实例属性,可变数据结构作为类属性需要注意的地方
- c语言中strtoint的用法,C++ String(字符串)和 int(整数) 互转