用c++把数字转换成字符串 30
输出BarPlot–ASimpleBarGraphPlotter:Inputanumberinrange[050]oranegativenumbertoterminate...
输出BarPlot – A Simple Bar Graph Plotter:
Input a number in range [0 50] or a negative number to terminate:
----------------------------------------------- | Enter Number: 6
| ====+> 6 | Enter Number: 12
| ====+====|=> 12 | Enter Number: 50
| ====+====|====+====|====+====|====+====|====+====> 50 | Enter Number: 53
| ERROR: 53 is not in acceptable range. | Enter Number: 33
| ====+====|====+====|====+====|==> 33 | Enter Number: 0
| 0
| Enter Number: 5
| ====> 5 | Enter Number: -1 ------------------------------------------------
BarPlot – End Plot by User Request 展开
Input a number in range [0 50] or a negative number to terminate:
----------------------------------------------- | Enter Number: 6
| ====+> 6 | Enter Number: 12
| ====+====|=> 12 | Enter Number: 50
| ====+====|====+====|====+====|====+====|====+====> 50 | Enter Number: 53
| ERROR: 53 is not in acceptable range. | Enter Number: 33
| ====+====|====+====|====+====|==> 33 | Enter Number: 0
| 0
| Enter Number: 5
| ====> 5 | Enter Number: -1 ------------------------------------------------
BarPlot – End Plot by User Request 展开
1个回答
展开全部
void fun(char* pstr)
{//注意:该函数只针对字符串中全是数字的情况,如果有其它字符,请重新判断处理
if(NULL == pstr)
return;
int strlength = strlen(pstr);
if(strlength <= 0)
return;
int *arr = new int[strlength+1];
memset(arr,0, strlength + 1);
int i = 0;
while(*(pstr + i) != '\0)
{
arr[i] = *(pstr + i) - '0';
++i;
}
for(i =0; i <= strlength)
cout<<arr[i]<<" ";
cout<<endl;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询