函数参数传递不成功
#include <iostream>unsigned long left(unsigned long num,unsigned ct);
char *letf(const char *str,int n=1);
int main()
{
using namespace std;
char *trip="hawail!! ";
unsigned long n=12345678;
int i;
char *temp;
for(i=1;i<10;i++)
{
cout<<left(n,1)<<endl;
temp=left(trip,i);
cout<<temp<<endl;
delete[]temp;
}
return 0;
}
unsigned long letf(unsigned long num,unsigned ct)
{
unsigned diguts=1;
unsigned n=num;
if(ct==0||num==0)
return 0;
while(n/=10)
diguts++;
if(diguts>ct)
{
ct=diguts-ct;
while(ct--)
num/=10;
return num;
}
else
{ return num;}
}
char *letf(const char * str,int n)
{
if(n<0)
n=0;
char *p=new char(n+1);
int i;
for(i=0;i<n&&str[i];i++)
p[i]=str[i];
while(i<=n)
p[i++]='\0';
return p;
错误提示:
}:\c++程序\zy_8_10\10.cpp(15) : error C2665: 'left' : none of the 2 overloads can convert parameter 1 from type 'char *'
Error executing cl
希望高手帮我解答
[ 本帖最后由 蜗牛进程 于 2009-11-2 19:31 编辑 ]