`

VC视频教程笔记(第12课)

    博客分类:
  • C++
阅读更多
http://www.sunxin.org/forum/thread/210.html?page=1
作者:虎非龙

第12课 文件操作
1.常量指针与指针常量的区分
  char ch[5]="lisi";
  const char *pStr=ch;//const在*之前,表明指针指向的内容为常量,即为常量指针
  char * const pStr=ch;//const在*之后,表明指针的地址不能改变,即为指针常量
  明白?
2.对文件读写的三种方法
  1.C中
    FILE *pFile=fopen("1.txt","w");
fwrite("http://www.sunxin.org",1,strlen("http://www.sunxin.org"),pFile);
//fseek(pFile,0,SEEK_SET);
//fwrite("ftp:",1,strlen("ftp:"),pFile);
//fwrite("http://www.sunxin.org",1,strlen("http://www.sunxin.org"),pFile);
fclose(pFile);*/
//fflush(pFile);
  2.C++中
/* ofstream ofs("4.txt");
ofs.write("http://www.sunxin.org",strlen("http://www.sunxin.org"));
ofs.close();*/
         要包括头文件 "fstream.h"
  3.MFC中 用CFile类,哈哈!简单好用
CFileDialog fileDlg(FALSE);
fileDlg.m_ofn.lpstrTitle="我的文件保存对话框";
fileDlg.m_ofn.lpstrFilter="Text Files(*.txt)\0*.txt\0All Files(*.*)\0*.*\0\0";
fileDlg.m_ofn.lpstrDefExt="txt";
if(IDOK==fileDlg.DoModal())
{
  CFile file(fileDlg.GetFileName(),CFile::modeCreate | CFile::modeWrite);
  file.Write("http://www.sunxin.org",strlen("http://www.sunxin.org"));
  file.Close();
}
  4.利用win32 API函数 CreateFile(),及WriteFile()
4.注册表读写
  1.对win.ini的读写
//::WriteProfileString("http://www.sunxin.org","admin","zhangsan");
/* CString str;
::GetProfileString("http://www.sunxin.org","admin","lisi",
  str.GetBuffer(100),100);
AfxMessageBox(str);*/
  2.注册表的读写
HKEY hKey;
DWORD dwAge=30;
RegCreateKey(HKEY_LOCAL_MACHINE,"Software\\http://www.sunxin.org\\admin",&hKey);
RegSetValue(hKey,NULL,REG_SZ,"zhangsan",strlen("zhangsan"));
RegSetValueEx(hKey,"age",0,REG_DWORD,(CONST BYTE*)&dwAge,4);
RegCloseKey(hKey);以上是写入
代码比较简单,不再详细介绍。本笔记也不是为介绍函数而存在的。嘿嘿
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics