我正在制作一个用于学习目的的C++头文件。它应该给我的数字的长度(是一个INT,浮动,双等),而不包括逗号。这里是我的代码:C++ #include宏名称必须是标识符
#ifndef NUMLEN_H
#define NUMLEN_H
#define <cstring>
int numlen (char numberLengthSample[]) //numlen - lenghth of the number, numberLengthSample - the number you put in.
{
int numberLengthDummy = strlen (numberLengthSample); //a temporary int used in counting the length
int numlenc = strlen (numberLengthSample); //the true length of the number
while (numberLengthDummy>0)
{
if (numberLengthSample[numberLengthDummy-1]=='.'||numberLengthSample[numberLengthDummy-1]==',')
{
numlenc--;
}
numberLengthDummy--;
}
return numlenc;
}
#endif // NUMLEN_H
但它给了我3个错误: 1)(3号线)宏名必须是标识符 2)(7号线) 'strlen的' 不是在这个范围内(显然申报) 3)(第5行(当从我的测试.cpp执行时))初始化'int numlen(char *)'的参数1 [-fpermissive] |
我试图寻找答案,但没有占上风。任何帮助,将不胜感激 :) 。