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():
Code:
ofstream outfile((username + ".dat").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>:
Code:
char filename[100];
strcpy(filename, username);
strcat(filename, ".dat");
ofstream outfile(filename);
Because you didn't post the rest of your code, those examples might not work for you, but that is the idea.