Boa tarde a todos! Estou com um problema em relação a essa estrutura que cria um Common Dialolg Box de abrir/salvar arquivo. No programa de teste abaixo, estou simplesmente tentando salvar os dados de uma classe e depois lê-los. #include <iostream>
#include <fstream>
#include <cstdlib>
#include <cstdio>
#include <windows.h>
using namespace std;
void createfile();
void savefile();
void loadfile();
class myclass {
int a;
int b;
int c;
public:
myclass(int j, int k, int l) { a=j; b=k; c=l; };
int geta() { return a; };
int getb() { return b; };
int getc() { return c; };
};
fstream tmpFile;
char cstrFileName [100];
int main()
{
cstrFileName[0] = '';
bool b = false;
int choice;
do {
cout << "1 - Create file\n2 - Load\n3 - Exit\n";
cin >> choice;
switch(choice)
{
case 1: { createfile(); continue; } break;
case 2: { loadfile(); continue; } break;
case 3: { exit(0); continue; } break;
default: b = true; system("cls");
}
} while(b);
system("pause");
}
void createfile()
{
myclass a(1, 1, 1);
OPENFILENAME ofn = {0};
ofn.hInstance = NULL;
ofn.hwndOwner = NULL;
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.lpstrFilter = "CL List Files*.clf*";
ofn.lpstrTitle = "Save list";
ofn.lpstrFile = cstrFileName;
ofn.nMaxFile = sizeof(cstrFileName);
ofn.Flags = OFN_HIDEREADONLY | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
if(GetSaveFileName(&ofn))
{
tmpFile.open(cstrFileName, ios::binary);
tmpFile.write((char *) &a, sizeof(myclass));
tmpFile.close();
}
}
void loadfile()
{
myclass b(0, 0, 0);
OPENFILENAME ofn = {0};
ofn.hInstance = NULL;
ofn.hwndOwner = NULL;
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.lpstrFilter = "CL List Files*.clf*";
ofn.lpstrTitle = "Open a file";
ofn.nMaxFile = sizeof(cstrFileName);
ofn.Flags = OFN_FILEMUSTEXIST |
OFN_HIDEREADONLY |
OFN_NONETWORKBUTTON |
OFN_PATHMUSTEXIST;
if(GetOpenFileName(&ofn))
{
tmpFile.open(cstrFileName, ios::binary);
tmpFile.read((char *) &b, sizeof(class myclass));
cout << endl;
cout << "A = " << b.geta() << endl;
cout << "B = " << b.getb() << endl;
cout << "C = " << b.getc() << endl;
tmpFile.close();
}
} O código executa, não há erros de compilação, mas nenhum arquivo é criado =\ Alguém pode me dar uma luz? Já tentei de tudo e nada parece adiantar. Bem, obrigado desde já :rolleyes: