- #include <cstdlib>
- #include <iostream>
- using namespace std;
- long ConvertToLong(char* pString)
- {
- char temp[20];
- int i=0;
- long result;
- while(*pString) //去掉小数点
- {
- if(*pString!='.')
- {
- temp[i++]=*pString;
- }
- pString++;
- }
- temp[i]='\\0';
- sscanf(temp,"%ld",&result); //字符串格式化成长整形
- return result;
- }
- int main(int argc, char *argv[])
- {
- char *input="0.1025";
- printf("%ld\\n",ConvertToLong(input));
- system("PAUSE");
- return 0;
- }
- //该片段来自于http://www.codesnippet.cn/detail/100920135788.html
来源: http://www.codesnippet.cn/detail/100920135788.html