c++ - strcpy was not declared in this scope? -


#include <iostream> #include <string> using namespace std;  int main() {     char buffer[20] = {'\0'};      cout << "enter line of text: " << endl;     string lineentered;     getline (cin, lineentered);      if ( lineentered.length() < 20 ){         strcpy(buffer, lineentered.c_str()); // strcpy. not declared in scope reason.         cout << "buffer contains: " << buffer << endl;     }      return 0; } 

this error:

main.cpp:14:43: error: 'strcpy' not declared in scope 

why having error?

the strcpy function in include file string.h. add:

#include <string.h> 

or, alternatively if want more c++ it,

#include <cstring> 

and use std::strcpy().


Comments