It depends on how username is declared. If it is a string (i.e. from the standard string class in <string>) then you need to put it inside parentheses and use .c_str():
If it is a C-style string (i.e. null terminated character array), then you can't add strings like that. You would need to use strcat in <cstring>:
ofstream outfile((username + ".dat").c_str());
Because you didn't post the rest of your code, those examples might not work for you, but that is the idea.