我正在製作一個用於學習目的的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] |
我試圖尋找答案,但沒有佔上風。任何幫助,將不勝感激 :) 。