#include <iostream>
using namespace std;
const int ArSize = 80;
char* left(const char* str, int n = 2); // 提取字符串str里边左边n 个,
void f(int a, int b, float c); // 函数中声明的变量x y z 可以跟函数定义中的变量不一样,函数声明的变量也可以不写,
int main()
{
char sample[ArSize];
cout << "Enter a string : \n";
cin.get(sample, ArSize);
char* ps = left(sample, 4);
cout << ps << endl;
delete[] ps;
ps = left(sample); // 这个时候使用默认的n = 2;
cout << ps << endl;
delete[] ps;
f(603, 12, 31);
return 0;
}
void f(int x, int, float z)
{
cout << x << endl;
//cout << y << endl; // 这里的 第二个变量可以不写,但是要保留着(因为在其它的地方已经使用了),这就是占位符参数,
cout << z << endl;
}
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;
}