tututuzxcv 2017-09-12 14:02 采纳率: 50%
浏览 376

使用文件夹的路径,程序问题出在哪

//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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥50 永磁型步进电机PID算法
    • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
    • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
    • ¥15 如何处理复杂数据表格的除法运算
    • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
    • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
    • ¥200 uniapp长期运行卡死问题解决
    • ¥15 latex怎么处理论文引理引用参考文献
    • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
    • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?