//use C++ iostream char *chError = (char *)new(char[50]); ifstream input; int cStrBuffer[1]; //read_buffer input.open(chFile1,ios::in);//the second parameter means istream if(input.fail()) { chError = "Error in opening the file:"; strcat(chError,chFile1); AfxMessageBox(chError); exit(1); } input.read((unsigned char *)&cStrBuffer,1);//the second parameter means //how many bytes you want to read
myfile.Open("your.txt",CFile::modeRead);
char txtbuffer[2048];
myfile.Read(txtbuffer,2048);txtbuffer即是读入的文本。英文和中文均可。
CString str;
file.Open("文件名.txt",CFile::modeRead);
file.ReadString(str);
file.Close;
MessageBox(str);
ReadString每读一次都是遇到'\n'才停
CFile myfile;
myfile.Open("your.txt",CFile::modeRead);
CString txtbuffer;
int filelength = myfile.GetLength();
myfile.Read(txtbuffer,filelength);
myfile.Close;
txtbuffer即是读入的文本.这样保证不会有截断的现象。实际上, shilong(银羽(★★倒计时250分)) 已经很完美了。
UNICODE编码.see more about
wchar_t,and BSTR
and it is not so hard!
{
CFile myfile;
myfile.Open("data/document.txt",CFile::modeRead);
char txtbuffer[2048];
myfile.Read(txtbuffer,2048);
str=txtbuffer;
return 1;
}
int CMyBmpDlgDlg::OnButton1()
{
CAboutDlg Dlg;
Dlg.DoModal();
char ttt[2084];
if(!LoadChTxt(ttt))
return 0;
GetDlgItem(IDC_STATIC)->SetWindowText(ttt);
Invalidate();
return 1;
}
{
CFile myfile;
myfile.Open("data/document.txt",CFile::modeRead);
myfile.Read(str,2048);
return 1;
}
int LoadChTxt(char *str)
{
CFile myfile;
myfile.Open("data/document.txt",CFile::modeRead);
char txtbuffer[2048];
myfile.Read(txtbuffer,2048);
strcpy(str,txtbuffer);
return 1;
}
str=txtbuffer
把str指向txtbuffer[2048]这段内存而char txtbuffer[2048];
是局部变量,当函数结束时,它就无郊了
ifstream input;
int cStrBuffer[1]; //read_buffer input.open(chFile1,ios::in);//the second parameter means istream
if(input.fail())
{
chError = "Error in opening the file:";
strcat(chError,chFile1);
AfxMessageBox(chError);
exit(1);
}
input.read((unsigned char *)&cStrBuffer,1);//the second parameter means
//how many bytes you want to read
用系统映象文件的方法读取这个文件,映象文件初始化后,你可以得到指向文件头的
一个指针,有了指针,操作这个文件就可以象操作内存数据一样了。 接下来一个字符一个字符读取,遇到字符值大于128,则判断这肯定是一个汉字的前
半部分,所以我们读取二个字符,这样就把一个汉字读取了。然后NEXT,判断下一个字符
的值。