int转std:string
时间: 2023-10-24 22:01:26 浏览: 100
要将int类型转换为std::string类型,可以使用std::to_string函数。将int类型的变量作为参数传递给std::to_string函数,就会返回一个对应的std::string类型的字符串。例如,如果要将int变量n转换为std::string类型,可以使用以下代码:
```cpp
int n = 11;
std::string str = std::to_string(n);
```
这样,str就会被赋值为"11"。需要注意的是,如果int变量n为负数,转换后的std::string类型的字符串会带有一个负号。另外,如果int变量n为0,则返回的std::string类型的字符串也会是"0"。<span class="em">1</span><span class="em">2</span>
#### 引用[.reference_title]
- *1* [std::string int 转换](https://blog.csdn.net/hanbo79/article/details/124117978)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *2* [c++ int 转 std::string](https://blog.csdn.net/qq_39941918/article/details/88539589)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文