c 常用函式

2021-07-16 02:20:45 字數 848 閱讀 5379

c++中常用的一些函式,記錄下來以防忘記!!!

首先,字串string類:

輸入:#include

string str;

getline(cin,str);

int len=str.length();

int ipos=str.find('a',6);//從str的第六個位置處開始查詢'a'

int ipos=str.rfind('a');//從後往前查詢

str.find_first_of,str.find_last_of

ipos==str.npos;//表示查詢失敗

str1==str2;//string類字串可以直接用==判斷字串是否相等

string str2=str+」hello」;//字串拼接

string word=str.substr(index_begin,length);//返回str中從index_begin開始的length個字元

字串轉數字(atoi):

int str2num(char* str)

while(*str==' ')

str++;

if(*str=='-')

flag=-1;

if(*str=='-' || *str=='+')

str++;

while(*str!='/0')

int tmp=*str-'0';

if(result>max || (result==max && tmp>remainder))

result=result*10+tmp;

}result=result*flag;

return result;

}

C 常用函式

1 datetime 數字型 system.datetime currenttime new system.datetime 1.1 取當前年月日時分秒 currenttime system.datetime.now 1.2 取當前年 int 年 currenttime.year 1.3 取當前月 ...

常用c 函式

字串是不是數字 static int isnumber const char z,int realnum z if realnum realnum 0 找到第乙個不是數字的位置 while isdigit z if z if realnum realnum 1 if z e z e if realn...

c 常用函式

1 datetime 數字型 system.datetime currenttime new system.datetime 1.1 取當前年月日時分秒 currenttime system.datetime.now 1.2 取當前年 int 年 currenttime.year 1.3 取當前月 ...