1. 程式人生 > >字符串轉整形

字符串轉整形

bsp c中 浮點 com color code 字符串數組 con strcpy

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);

字符串轉整形