本人基本小白一只,下周二要交的大作业,求各位大神帮忙~
要求是基于对话框编写一个通讯录程序。之前有做过控制台的,用的是i/o流输入输出,但是把原来的string改成CString了之后输出的都是乱码。
ofstream outfile ("AddressBook.txt",ios::out|ios::app);//打开文件
outfile<<name<<" "<<birthYear<<" "<<birthMonth<<" "<<birthDay<<" "<<telnumber<<" "<<email<<'\n';
//name,telnumber,email,为cstring型,birthYear,birthMonth,birthDay,为int型
要求是基于对话框编写一个通讯录程序。之前有做过控制台的,用的是i/o流输入输出,但是把原来的string改成CString了之后输出的都是乱码。
ofstream outfile ("AddressBook.txt",ios::out|ios::app);//打开文件
outfile<<name<<" "<<birthYear<<" "<<birthMonth<<" "<<birthDay<<" "<<telnumber<<" "<<email<<'\n';
//name,telnumber,email,为cstring型,birthYear,birthMonth,birthDay,为int型
CStringW strSrcW(strSrc);const char* p1 = strSrcA;
const WCHAR* p2 = strSrcW;string strDesA((LPCSTR)strSrcA);
wstring strDesW((LPCWSTR)strSrcW);
貌似我blog还要写进得一篇
/*
记得在开头包含下面一堆头文件
#include<io.h>
#include<sys\stat.h>
#include<stdio.h>
#include<fcntl.h>
*/
FILE*stream;
int handle;
char buf[]="test.txt";
char* est="测试:\n";
CString timestr = "输出内容、、、、\n";
//如果需要格式化整数
// int md = 99;
// timestr.Format("%d",md);
//这样写入的就是 99 了。
//用open函数将文件以O_TEXT方式打开
handle=open(buf, O_RDWR | O_CREAT, S_IWRITE | S_IREAD );
//如果打开失败,打印错误信息
if(handle==-1)
{
perror("can not open file!");
MessageBox(NULL,"不能打开文件!","提示:",MB_OK);
}
else
{
//将文件以流方式打开
stream=fdopen(handle,"a+");
//如果打开失败,提示出错
if(stream==NULL)
{
perror("fdopen failed!");
MessageBox(NULL,"不能打开文件!","提示:",MB_OK);
close(handle);
}
//打开成功
else
{
//写入字符串
fseek(stream,-1,SEEK_END);//指针移到文件末尾
fwrite(est,strlen(est),1,stream);
fwrite(timestr,strlen((LPCTSTR)timestr),1,stream);
//关闭文件
fclose(stream);
}
}
pfile=fopen(_T("E:\\love.txt"),_T("w+")); //打开E盘下的love.txt文件,如没有则创建CString _strtime(_T(""));
CTime t=CTime::GetCurrentTime();//获取系统时间
g_strtime=t.Format(_T(" %y 年 %m 月 %d 日"));
fwrite(g_strtime,1,g_strtime.GetLength(),pfile); //将系统时间写入pfile指向的txt
pfile=fopen(_T("E:\\love.txt"),_T("w+")); //打开E盘下的love.txt文件,如没有则创建CString _strtime(_T(""));
CTime t=CTime::GetCurrentTime();//获取系统时间
g_strtime=t.Format(_T(" %y 年 %m 月 %d 日"));
fwrite(g_strtime,1,g_strtime.GetLength(),pfile); //将系统时间写入pfile指向的txt//我最喜欢FILE了 ,多方便,和控制台程序一样方便