读文件 怎样将.txt文本文件中的内容(包括汉字)读入到wchar_t类型的数组中? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 1、fgets();然后char转wchar_t2、用CString,CFile,然后wcscpy(); 可参考:FILE* fp=fopen("路径+文件名.txt","a+");char buf[大小自定] = {0};//定义缓存区for(int j=0;j<文本行数;j++){fgets(buf,1024,fp); //读取一整行 把char类型的buf转换为wchar_t类型存起来(略)} 个人觉得最简单的不是cfile是那个cstudiofile,下面是我修改阿帕奇配置文件的端口的代码CString confpath=g_CurrentDirectoryPath.Left(g_CurrentDirectoryPath.GetLength()-3)+_T("apache\\conf\\httpd.conf"); CStdioFile httpconf; bool bret=httpconf.Open(confpath,CStdioFile::modeRead); //WriteLogAlways1(_T("C:\\logprint.txt"),_T("httpconf Open: ")+confpath); if (bret) { CString strLine; CStdioFile temp; if(!temp.Open(confpath+_T(".tmp"),CFile::modeCreate | CFile::modeReadWrite)) { int iii=GetLastError(); CString aaa; aaa.Format(_T("%d"),iii); AfxMessageBox(_T("Error:")+aaa); } while(httpconf.ReadString(strLine)) { int i=strLine.Find(_T("Listen")); if (i==0) { temp.WriteString(_T("Listen ")+setport); temp.Write(_T("\n"),1); } else { //WriteLogAlways1(_T("C:\\logprint.txt"),_T("temp write: ")+strLine); //AfxMessageBox(_T("temp write: ")+strLine); temp.WriteString(strLine); temp.Write(_T("\n"),1); } } temp.Close(); httpconf.Close(); DeleteFile(confpath); CopyFile(confpath+_T(".tmp"),confpath,FALSE); DeleteFile(confpath+_T(".tmp")); CFile和CStdiofile自己百度下,全是讲解怎么使用的。 VC MFC 如何修改选项卡标签的颜色(字体和背景) 如何使用背景图片将对话框覆盖(包括标题栏)? 在线急问,如何使用winrar的命令行压缩文件 兄弟姐妹们,江湖救急,关于图片存储得问题.来者有分!!! 要调整图片的亮度、对比度,是怎么做的呀? 急!急!急!!!求聊天程序vc做的(代码越少越好)周五交作业 我是新手请给与帮助!!!(winrunner) 有趣的多字拆分算法! 对给出建议者,将送上我的拆字源程序共同探讨。 求:图象算法(物体追踪) 菜鸟问题:Debug显示的窗口在哪儿 基于TCP/IP socket文件传输 外网传输数据丢失 看看下面的代码 帮忙看看问题所在~
2、用CString,CFile,然后wcscpy();
FILE* fp=fopen("路径+文件名.txt","a+");
char buf[大小自定] = {0};//定义缓存区
for(int j=0;j<文本行数;j++)
{
fgets(buf,1024,fp); //读取一整行
把char类型的buf转换为wchar_t类型存起来(略)
}
CStdioFile httpconf;
bool bret=httpconf.Open(confpath,CStdioFile::modeRead);
//WriteLogAlways1(_T("C:\\logprint.txt"),_T("httpconf Open: ")+confpath);
if (bret)
{
CString strLine;
CStdioFile temp;
if(!temp.Open(confpath+_T(".tmp"),CFile::modeCreate | CFile::modeReadWrite))
{
int iii=GetLastError();
CString aaa;
aaa.Format(_T("%d"),iii);
AfxMessageBox(_T("Error:")+aaa);
}
while(httpconf.ReadString(strLine))
{
int i=strLine.Find(_T("Listen"));
if (i==0)
{
temp.WriteString(_T("Listen ")+setport);
temp.Write(_T("\n"),1);
}
else
{
//WriteLogAlways1(_T("C:\\logprint.txt"),_T("temp write: ")+strLine);
//AfxMessageBox(_T("temp write: ")+strLine);
temp.WriteString(strLine);
temp.Write(_T("\n"),1);
}
}
temp.Close();
httpconf.Close();
DeleteFile(confpath);
CopyFile(confpath+_T(".tmp"),confpath,FALSE);
DeleteFile(confpath+_T(".tmp"));