- 輸入可以以字符串來接收
方法一:字符數(shù)組
char N[MAX];
scanf("%s",N); //輸入的整數(shù)N氨肌,以字符串接收
方法二:字符串浮入,此時只可以使用cin和cout作為輸入輸出
string s;
cin >>s;
- 字符轉(zhuǎn)化為數(shù)字烦周,使用ASCALL碼
//利用ascall碼的方式,字符1變?yōu)閿?shù)字1
int to_number(char c)
{
int a = c - '0'; //0的ascall碼為48抬伺,1的ascall碼為49
return a;
}
- 數(shù)字變?yōu)樽址唬褂胻o_string()方法
#include <string>
using namespace std;
int a = 123;
string s = to_string(a);
- 字符串string變?yōu)檎妥兞縤nt,使用stoi()方法峡钓,注意是否超過了int的表示范圍
#include <string>
using namespace std;
string s = "123456";
int i = stoi(s);
- 單詞:
- a non-negative integer: 一個非負整數(shù)
最后編輯于 :
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者