我一直在使用Big C++中的一些程序,在我复制 append.cpp 后,Eclipse'strlen' was not declared in this scope
在第 8 行告诉我。我在网上查看了一下,我认为是因为我必须包含该<cstring>
库,但是没有解决它。怎么了?
附加.cpp:
#include <iostream>
using namespace std;
void append(char s[], int s_maxlength, const char t[])
{
int i = strlen(s); // error occurs here
int j = 0;
while(t[j] != '\0' && i < s_maxlength)
{
s[i] = t[j];
i++;
j++;
}
//Add zero terminator
s[i] = '\0';
}
int main()
{
const int GREETING_MAXLENGTH = 10;
char greeting[GREETING_MAXLENGTH + 1] = "Hello";
char t[] = ", World!";
append(greeting, GREETING_MAXLENGTH, t);
cout << greeting << "\n";
return 0;
}