Why does the following code not work?
#include <iostream>
#include <string>
int main(){
char filename[20];
cout << "Type in the filename: ";
cin >> filename;
strcat(filename, '.txt');
cout << filename;
}
It should concatenate “.txt” on the end of whatever filename is inputted
Also, when I try to compile it (with g++) this is the error message

Use double quotes instead of single quotes.
In C++, single quotes indicate a single character, double quotes indicate a sequence of characters (a string). Appending an
Lbefore the literal indicates that it uses the wide character set:The ordinary string literal is usually ASCII, while the wide string literal is usually some form of Unicode encoding (although the C++ language doesn’t guarantee this – check your compiler documentation).
The compiler warning mentions
intbecause the C++ standard (2.13.2/1) says that character literals that contain more than onecharactually has typeint, which has an implementation defined value.If you’re using C++ though, you’re better off using
std::stringinstead, as Mark B has suggested: