tututuzxcv 2017-09-12 13:57 采纳率: 50%
浏览 532

要使用选择的文件夹路径,这程序问题在哪

//DISPLAY 6.2 File I/O with Checks on open
//Reads three numbers from the file infile.dat, sums the numbers,
//and writes the sum to the file outfile.dat.
#include
#include
#include
#include
#include
#include
#include
#define NO_WIN32_LEAN_AND_MEAN
#include

using namespace std;
CString GetSavePath();
int main()
{
GetSavePath();
CString x;
x = GetSavePath();
cout << x << endl;
ifstream in_stream;
ofstream out_stream;

in_stream.open("x//.txt");
if (in_stream.fail())
{
    cout << "Input file opening failed.\n";
    exit(1);
}

out_stream.open("x//.txt", ios::app);
if (out_stream.fail())
{
    cout << "Output file opening failed.\n";
    exit(1);
}

int first, second, third;
in_stream >> first >> second >> third;
out_stream << "The sum of the first 3\n"
    << "numbers in infile.dat\n"
    << "is " << (first + second + third)
    << endl;

in_stream.close();
out_stream.close();

return 0;

}

CString GetSavePath()
{

CString strpath;

TCHAR Buffer[MAX_PATH];
BROWSEINFO bi;
ZeroMemory(&bi, sizeof(BROWSEINFO));
bi.hwndOwner = NULL;
bi.ulFlags = BIF_RETURNONLYFSDIRS;    //要求返回文件系统的目  

bi.ulFlags = BIF_NEWDIALOGSTYLE;        //窗口可以调整大小,有新建文件夹按钮  

bi.pszDisplayName = Buffer;           //此参数如为NULL则不能显示对话框   
bi.lpszTitle = _T("请选择文件夹");
bi.lpfn = NULL;


LPITEMIDLIST pIDList = SHBrowseForFolder(&bi);//调用显示选择对话框  
if (pIDList)
{
    SHGetPathFromIDList(pIDList, Buffer);
    //取得文件夹路径到Buffer里  

    strpath.Format(_T("%s"), Buffer);
}
else
{
    strpath = _T("");  // 用户点了取消  
}

LPMALLOC lpMalloc;
if (FAILED(SHGetMalloc(&lpMalloc)))
    strpath = _T("");


//释放内存  
lpMalloc->Free(pIDList);
lpMalloc->Release();

return strpath;

}

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 C# P/Invoke的效率问题
    • ¥20 thinkphp适配人大金仓问题
    • ¥20 Oracle替换.dbf文件后无法连接,如何解决?(相关搜索:数据库|死循环)
    • ¥15 数据库数据成问号了,前台查询正常,数据库查询是?号
    • ¥15 算法使用了tf-idf,用手肘图确定k值确定不了,第四轮廓系数又太小才有0.006088746097507285,如何解决?(相关搜索:数据处理)
    • ¥15 彩灯控制电路,会的加我QQ1482956179
    • ¥200 相机拍直接转存到电脑上 立拍立穿无线局域网传
    • ¥15 (关键词-电路设计)
    • ¥15 如何解决MIPS计算是否溢出
    • ¥15 vue中我代理了iframe,iframe却走的是路由,没有显示该显示的网站,这个该如何处理