C++中 string类以int型输出

先调用string的c_str(),函数,该函数一个指向正规C字符串的指针, 内容与本字符串相同,然后调用atoi()函数就可以了,下面是一个简单的测试程序:

#include<iostream>

using namespace std;

   
 int main(){
     
     string str = "12345";
     
     cout << atoi(str.c_str())<<endl;           
   

    return ;
}
posted @ 2012-04-03 11:41  Tail。  阅读(374)  评论(0编辑  收藏  举报