Use double quotes instead of single quotes.
strcat(filename, ".txt");
In C++, single quotes indicate a single character, double quotes indicate a sequence of characters (a string). Appending an L
before the literal indicates that it uses the wide character set:
".txt" // <--- ordinary string literal, type "array of const chars"
L".txt" // <--- wide string literal, type "array of const wchar_ts"
'a' // <--- single ordinary character, type "char"
L'a' // <--- single wide character, type "wchar_t"
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 int
because the C++ standard (2.13.2/1) says that character literals that contain more than one char
actually has type int
, which has an implementation defined value.
If you're using C++ though, you're better off using std::string
instead, as Mark B has suggested:
#include <iostream>
#include <string>
int main(){
std::string filename;
std::cout << "Type in the filename: ";
std::cin >> filename;
filename += ".txt";
std::cout << filename;
}