字符串转整形

1.c_str()的用法:

C中没有string,所以函数c_str()就是将C++的string转化为C的字符串数组,c_str()生成一个const char *指针,指向字符串的首地址。

char *p=s[10];

string a="welcome";

strcpy(p,a.c_str());

cout<<p;

2.字符串转整型:

  1.

int cnt=0;
while(s[i]>='0'&&s[i]<='9')
        cnt=cnt*10+s[i++]-'0';

  2.

#include<stdlib.h>
    char str[]= "1024";
    a = atoi(str);

3.字符串转浮点型:

#include<stdlib.h>
    a=atof(str);
原文地址:https://www.cnblogs.com/astonc/p/10139663.html