源码如下:
#include "stdafx.h"
#include
using namespace std;
unsigned long left(unsigned long num, unsigned ct);
char * left(const char * str, int n = 1);
int main(int argc, char* argv[])
{
char * trip = "Hawaii!!";
unsigned long n = 12345678;
int i;
char* temp;
for (i = 1; i<10; i++)
{
cout << left(n, i) << endl;
temp = left(trip, i);
cout << temp << endl;
delete[] temp;
}
return 0;
}
unsigned long lfet(unsigned long num, unsigned ct)
{
int digits = 1;
while (num /= 10)
digits++;
ct = digits - ct;
while (ct--)
num /= 10;
return num;
}
char * left(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;
}
求大神指教!!
错误如下:
1-错误 LNK1120 1 个无法解析的外部命令 exer D:\cpp\exer\Debug\exer.exe 1
严重性 代码 说明 项目 文件 行
2-错误 LNK2019 无法解析的外部符号 "unsigned long __cdecl left(unsigned long,unsigned int)" (?left@@YAKKI@Z),该符号在函数 _main 中被引用 exer D:\cpp\exer\exer.obj 1
谢谢!!