VC++中文件读写汇总

1,读


A法:
  CString strFileName = "C:\dd.txt";

  std::ifstream in;

  std::locale::global(std::locale(""));
  in.open(strFileName);
  std::locale::global(std::locale("C"));
  std::string line;

  while(getline(in, line))
  {
    cout<<line<<endl;
}

B法:

char readBuffer[500];      // 存放读取数据的缓存

CFile file(_T("e:\1.txt"), CFile::modeCreate | CFile::modeReadWrite);  

// 读取100个字节的数据到存放读取数据的缓存的readBuffer + lOff位置处
int nRet = file.Read(readBuffer , 100);  //100为希望读到长度, nRet为实际读到的长度
file.close();





未完待续。。。。。。






原文地址:https://www.cnblogs.com/skyhuangdan/p/5486774.html