2017-08-27 74 views
0

我想找到一種方法將字符串中的數字轉換爲整數。 我能找到字符串中的數字使用isnum函數,但問題是如何使它成爲整數將部分字符串轉換爲turbo C++中的整數

+1

閱讀[?我爲什麼不應該使用的Turbo C++](https://stackoverflow.com/questions/1961828/why-should-i-not- use-turbo-c) –

回答

1

我認爲你需要的是atoi函數。

下面是從cplusplus.com代碼示例:

/* atoi example */ 
#include <stdio.h>  /* printf, fgets */ 
#include <stdlib.h>  /* atoi */ 

int main() 
{ 
    int i; 
    char buffer[256]; 
    printf ("Enter a number: "); 
    fgets (buffer, 256, stdin); 
    i = atoi (buffer); 
    printf ("The value entered is %d. Its double is %d.\n",i,i*2); 
    return 0; 
} 
+0

@RahulRaman只有一個角色?只是'a-'0''。 – xmcp