#include <iostream>
#include <string>
using namespace std;
int main()
{
char Buffer[20] = {'\0'};
cout << "Enter a line of text: " << endl;
string LineEntered;
getline (cin, LineEntered);
if ( LineEntered.length() < 20 ){
strcpy(Buffer, LineEntered.c_str()); // This strcpy. is not declared in scope for some reason.
cout << "Buffer contains: " << Buffer << endl;
}
return 0;
}
This is the error:
main.cpp:14:43: error: 'strcpy' was not declared in this scope
Why is it having this error?
The strcpy
function is in the include file string.h
. So add:
#include <string.h>
Or, alternatively if you want to be more C++ about it,
#include <cstring>
and use std::strcpy()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With