修改并运行通过,你自己看吧,有不明白的再问
#include
#include
#include
#include
using namespace std;
LPTSTR SlotName = TEXT("sample_mailslot.txt");
BOOL WriteSlot(HANDLE hSlot, LPCTSTR lpszMessage)
{
BOOL fResult;
DWORD cbWritten;
fResult = WriteFile(hSlot, lpszMessage, (DWORD)(lstrlen(lpszMessage)+1)*sizeof(TCHAR), &cbWritten, (LPOVERLAPPED) NULL);
if (!fResult)
{
printf("WriteFile failed with %d.\n", GetLastError());
return FALSE;
}
printf("Slot written to successfully.\n");
return TRUE;
}
int main()
{
HANDLE hFile;
string strtmp;
wstring wstrtmp;
hFile = CreateFile(SlotName, GENERIC_WRITE, FILE_SHARE_READ, (LPSECURITY_ATTRIBUTES) NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, (HANDLE) NULL);
if (hFile == INVALID_HANDLE_VALUE)
{
printf("CreateFile failed with %d.\n", GetLastError());
return FALSE;
}
bool bFlag = true;
while(bFlag)
{
cout << "input your order please:" << endl;
cin >> strtmp;
if (strtmp == "exit")
{
bFlag = false;
}
else
{
std::wstringstream wstream;
std::stringstream stream;
stream << strtmp;
wstream << stream;
wstream >> wstrtmp;
std::cout <
}
}
CloseHandle(hFile);
}
修改并运行通过,你自己看吧,有不明白的再问
#include
#include
#include
#include
using namespace std;
LPTSTR SlotName = TEXT("sample_mailslot.txt");
BOOL WriteSlot(HANDLE hSlot, LPCTSTR lpszMessage)
{
BOOL fResult;
DWORD cbWritten;
fResult = WriteFile(hSlot, lpszMessage, (DWORD)(lstrlen(lpszMessage)+1)*sizeof(TCHAR), &cbWritten, (LPOVERLAPPED) NULL);
if (!fResult)
{
printf("WriteFile failed with %d.\n", GetLastError());
return FALSE;
}
printf("Slot written to successfully.\n");
return TRUE;
}
int main()
{
HANDLE hFile;
string strtmp;
wstring wstrtmp;
hFile = CreateFile(SlotName, GENERIC_WRITE, FILE_SHARE_READ, (LPSECURITY_ATTRIBUTES) NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, (HANDLE) NULL);
if (hFile == INVALID_HANDLE_VALUE)
{
printf("CreateFile failed with %d.\n", GetLastError());
return FALSE;
}
bool bFlag = true;
while(bFlag)
{
cout << "input your order please:" << endl;
cin >> strtmp;
if (strtmp == "exit")
{
bFlag = false;
}
else
{
std::wstringstream wstream;
std::stringstream stream;
stream << strtmp;
wstream << stream;
wstream >> wstrtmp;
std::cout <
}
}
CloseHandle(hFile);
wstringstream是创建类型在 wchar_t 模板参数专用的 basic_stringstream
stringstream是字符串流。它将流与存储在内存中的string对象绑定起来。在多种数据类型之间实现自动格式化
#include
#include
#include
#include
using namespace std;
LPTSTR SlotName = TEXT("\\\\.\\mailslot\\sample_mailslot");
BOOL WriteSlot(HANDLE hSlot, LPTSTR lpszMessage)
{
BOOL fResult;
DWORD cbWritten;
fResult = WriteFile(hSlot,
lpszMessage,
(DWORD) (lstrlen(lpszMessage)+1)*sizeof(TCHAR),
&cbWritten,
(LPOVERLAPPED) NULL);
if (!fResult)
{
printf("WriteFile failed with %d.\n", GetLastError());
return FALSE;
}
printf("Slot written to successfully.\n");
return TRUE;
}
int main()
{
HANDLE hFile;
string strtmp;
wstring wstrtmp;
hFile = CreateFile(SlotName,
GENERIC_WRITE,
FILE_SHARE_READ,
(LPSECURITY_ATTRIBUTES) NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
(HANDLE) NULL);
if (hFile == INVALID_HANDLE_VALUE)
{
printf("CreateFile failed with %d.\n", GetLastError());
return FALSE;
}
bool bFlag = true;
while(bFlag);
{
cout << "input your order please:" << endl;
cin >> strtmp;
if (strtmp == "exit")
{
bFlag = false;
}
else
{
std::wstringstream wstream;
std::stringstream stream;
stream << wstrtmp; // error C2679出现的地方
stream >> strtmp;
std::cout <
}
}
CloseHandle(hFile);
}
压标亘古未有下大雨夺下大雨夺下大雨