string - C++ strlen error in Big C++ -
i've been working through of programs in big c++ , after copied append.cpp, eclipse telling me 'strlen' not declared in scope
on line 8. took online, , thought because had include <cstring>
library, didn't solve it. what's wrong?
append.cpp:
#include <iostream> using namespace std; void append(char s[], int s_maxlength, const char t[]) { int = strlen(s); // error occurs here int j = 0; while(t[j] != '\0' && < s_maxlength) { s[i] = t[j]; i++; j++; } //add 0 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; }
including <cstring>
header should solve (should have solved) issue. suspicion correct: eclipse being dumb, gave false positive.
in cases this, don't believe ide! try compile source text - if compiler accepts it, static analysis tool in ide wrong.
Comments
Post a Comment