c++int转为string
时间: 2023-09-10 08:09:32 浏览: 109
如何将int 转为string(c/c++)
在C++中,可以使用to_string()函数将int类型转换为string类型。例如,如果有一个整数变量i,可以使用to_string(i)将其转换为字符串。以下是一个示例代码:
```cpp
#include <iostream>
#include <string>
using namespace std;
int main() {
int i = 10;
string str = to_string(i);
cout << "int转换为string: " << str << endl;
return 0;
}
```
运行结果为:
```
int转换为string: 10
```
这样就将整数转换为了字符串。\[1\]
#### 引用[.reference_title]
- *1* [C++ int与string相互转换](https://blog.csdn.net/wangcheng_BI/article/details/124363001)[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^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* *3* [C++ int与string的相互转换](https://blog.csdn.net/samsara1999/article/details/121210899)[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^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文