I am getting an error when I run this piece of code
string line;
getline (myfile,line);
char file_input[15];
strncpy(file_input, line, 6);
cout << line << endl;
Error – cannot convert ‘std::string’ to ‘const char*’ for argument ‘2’ to ‘char* strncpy(char*, const char*, size_t)’
How to get rid of this?
But why would you want the fixed-length buffer
file_inputin the first place? It would be safer to construct it as a newstd::stringcontaining the first five characters inline: