用VC++怎么将TXT文件中的字符存到数组里?

来源:百度知道 编辑:UC知道 时间:2024/06/03 17:03:11
假设有一个TXT文件里存的都是字母,要怎样打开并存到数组里?
又怎么将之存为字母的ASCII形式?
TXT文件要放在哪才能打开?是与C++文件同个文件夹吗?
急用呀!发现手上的书居然都没讲,没天理呀!

void Readtxt(char *pbuf)
{
CFile file("test.txt",CFile::modeRead); //test.txt与c++文件同一个文件夹
DWORD dwFileLen;
dwFileLen = file.GetLength();
delete []pbuf;
char *pbuf=new char[dwFileLen];
pbuf = new char[dwFileLen+1];
pbuf[dwFileLen] = 0;
file.Read(pbuf,dwFileLen);
file.Close();
}
--------------------------------------------------------------------
void Readtxt(char *pbuf)//打开指定文本
{
CFileDialog openDlg(TRUE); //TRUE说明这个为打开对话框
openDlg.m_ofn.lpstrTitle = "TXT文件打开对话框";
openDlg.m_ofn.lpstrFilter = "Text type(*.txt)\0*.txt\0All files(*.*)\0*.*\0\0";//设置扩展名
openDlg.m_ofn.lpstrDefExt = "txt"; //设置默认扩展名
if(IDOK == openDlg.DoModal())
{
CFile file(openDlg.GetFileName(),CFile::modeRead);
DWORD dwFileLen;
dwFileLen = file.GetLength();
delete []pbuf;
char *pbuf=new char[dwFileLen];
pbuf = new char[dwFileLen+1];<