65,210
社区成员
发帖
与我相关
我的任务
分享
fstream fp("a.txt");
if(!fp)
return 0;
fp<<"姓名"<<endl;
fp.close();
HANDLE hf = CreateFile(TEXT("a.txt"),GENERIC_WRITE,FILE_SHARE_READ,NULL,CREATE_ALWAYS,NULL,NULL);
if(hf == INVALID_HANDLE_VALUE)
return FALSE;
//utf-16转utf-8
int Size = WideCharToMultiByte(CP_UTF8, 0, pspvSubject->Value.lpszW, -1, NULL, 0,NULL,NULL);
char *temp = new char[Size];
if( !temp )
{
delete []temp;
OutputDebugString(L"初始化失败!");
return FALSE;
}
WideCharToMultiByte (CP_UTF8, 0, pspvSubject->Value.lpszW, -1, temp, Size,NULL,NULL);
DWORD dwWritten=0;
if( !WriteFile(hf,temp,strlen(temp)*sizeof(char),&dwWritten,NULL) )
{
CloseHandle(hf);
return FALSE;
}
CloseHandle(hf);
#include"iostream"
#include"fstream"
using namespace std;
int main()
{
ifstream in_stream;
ofstream out_stream;
char file_name[15];
cout<<"Please enter the name of the file"<<endl;
cin>>file_name;
in_stream.open(file_name)
if(in_stream.fail())//判断打开是否成功
{
out_stream.open(file_name);//创建改文件
}
in_stream.close();
out_stream.close();
in_stream.open(file_name);
...//你要执行的操作
return 0;
}
CString fileName ;
fileName = "d:\\MsgFile.txt";
if (msgfile.Open(fileName.GetBuffer(0), CFile::modeCreate | CFile::modeWrite| CFile::modeNoTruncate))
{
msgfile.SeekToEnd();
msgfile.Write(stemp, stemp.GetLength());
msgfile.Close();
}