#include <fstream>
#include <iostream>
#include <vector>
#include <string>
#include <windows.h>
#define FILEPAWD "./passwd.txt"
#define SALEINFO "./saleinfo.txt"
class MFile
{
public:
MFile();
MFile(const char *path);
bool Open(const char *path);
bool Save(const char *path, vector<string> in);
vector<string> vstr;
};
MFile::MFile()
{
}
MFile::MFile(const char *path)
{
Open(path);
}
bool MFile::Open(const char *path)
{
try
{
vstr.clear();
string str;
ifstream in;
in.open(path, ios::binary | ios::in);
if (!in.is_open()) return false;
while (getline(in,str)){
vstr.push_back(str);
}
in.close();
return true;
}
catch (...){
return false;
}
}
bool MFile::Save(const char *path, vector<string> in)
{
try
{
ofstream out;
out.open(path, ios::out | ios::binary);
if (!out.is_open()) return false;
for (auto it : in)
{
out << it << "\r\n";
}
out.close();
return true;
}
catch (...)
{
return false;
}
}
int main()
{
unsigned long size = GetCurrentDirectory(0, NULL);
wchar_t path[1024];
char str[1024] = "";
if (GetCurrentDirectory(size, path) != 0)
{
WideCharToMultiByte(CP_ACP, 0, path, -1, str, 1024, NULL, NULL);
}
MFile f(FILEPAWD);
f.Save(FILEPAWD, { { "123|223" }, { "222|11" } });
return 0;
}