C++ string 与 int 类型数据的互相转化

一、int 类型转换为 string 类型

 string s=to_string(asum+bsum);//int 转化为 string

string/char 转换为 int 类型

1、首先将 字符串string 转为 C语言中的 const char* 类型(使用 _c.str()函数)

2、将 const char* 转为 int 类型(使用atoi(const char *)函数)

    if( num == atoi( nums.c_str() ) ) {
        cout << "num == nums" << endl; 
    } else{
        cout << "num 与 nums 不相等@" << endl;
    }

 

posted @ 2022-01-19 15:18  晓风霜度-  阅读(246)  评论(0)    收藏  举报