C++只生成一个实例的代码
#include <iostream>
#include <fstream>
#include <Windows.h>
#include <WinError.h>
using namespace std;
void main()
{
HANDLE h =CreateMutex(NULL, FALSE, TEXT("133"));
if(GetLastError() == ERROR_ALREADY_EXISTS)
{
return;
}
char szInput[256];
char szCreate[256];
char ch;
cin >> szInput;
ifstream input(szInput, ios::in);
if (input.fail())
{
cout << "源文件不能打开" << endl;
return;
}
cin >> szCreate;
ofstream objectFile(szCreate);
if (objectFile.fail())
{
cout << "目标文件不能创建" << endl;
return;
}
input.unsetf(ios::skipws);
while(input >> ch)
{
objectFile << ch;
}
input.close();
objectFile.close();
int wait;
cin >> wait;
}