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();





未完待续。。。。。。






posted @ 2014-12-15 23:43  水蒸蛋不好吃  阅读(133)  评论(0编辑  收藏  举报