I want to find a way to save a file to a desktop. Since every user has different user name, I found following code will help me find the path to someone else’s desktop. But how can I save the following to desktop? file.open(appData +"/.txt"); doesn't work. Can you please show me an example?
#include <iostream>
#include <windows.h>
#include <fstream>
#include <direct.h>
#include <shlobj.h>
using namespace std;
int main ()
{
    ofstream file;  
    TCHAR appData[MAX_PATH];
    if (SUCCEEDED(SHGetFolderPath(NULL,
                                  CSIDL_DESKTOPDIRECTORY | CSIDL_FLAG_CREATE,
                                  NULL,
                                  SHGFP_TYPE_CURRENT,
                                  appData)))
    wcout << appData << endl; //This will printout the desktop path correctly, but
    file.open(appData +"file.txt"); //this doesn't work
    file<<"hello\n";
    file.close();
    return 0;
}
Microsoft Visual Studio 2010, Windows 7, C++ console
UPDATED:
#include <iostream>
#include <windows.h>
#include <fstream>
#include <direct.h>
#include <shlobj.h>
#include <sstream> 
using namespace std;
int main ()
{
    ofstream file;  
    TCHAR appData[MAX_PATH];
    if (SUCCEEDED(SHGetFolderPath(NULL,
                                  CSIDL_DESKTOPDIRECTORY | CSIDL_FLAG_CREATE,
                                  NULL,
                                  SHGFP_TYPE_CURRENT,
                                  appData)))
    wcout << appData << endl; //This will printout the desktop path correctly, but
    std::ostringstream file_path; 
    file_path << appData << "\\filename.txt";//Error: identifier file_path is undefined
    file.open(file_path.str().c_str()); //Error:too few arguments in function call
    return 0;
}
 
     
     
     
    