准备用ifstream来读文件,因为可以判断是否到结尾。
在doc中写了readPointFile的函数。
BOOL COGLEventDoc::readPointFile(CFile& File){
string tempName=File.GetFilePath();
std::ifstream _input_stream(tempName.c_str());
_input_stream>>tempName;
......
}
想打开的是txt格式的文件,测试的文件路径为C:\Users\vip\Downloads\point.txt
通过设断点知道, 在tempName初始化后值为“C:\Users\vip\Downloads\point.txt”,CFile参数的传入没问题。
但是,用if(_input_stream)发现条件不成立。
用_input_stream>>tempName,也没成功读入。
文件的第一行是JHS1-1-1 298470.365 516184.435 12.2 30.36不知道ifstream在哪里用错了?
namespace、header file都没有问题。
谢谢!
在doc中写了readPointFile的函数。
BOOL COGLEventDoc::readPointFile(CFile& File){
string tempName=File.GetFilePath();
std::ifstream _input_stream(tempName.c_str());
_input_stream>>tempName;
......
}
想打开的是txt格式的文件,测试的文件路径为C:\Users\vip\Downloads\point.txt
通过设断点知道, 在tempName初始化后值为“C:\Users\vip\Downloads\point.txt”,CFile参数的传入没问题。
但是,用if(_input_stream)发现条件不成立。
用_input_stream>>tempName,也没成功读入。
文件的第一行是JHS1-1-1 298470.365 516184.435 12.2 30.36不知道ifstream在哪里用错了?
namespace、header file都没有问题。
谢谢!
判斷文件是否已經讀到結尾 對FILE* 用feof還不是可以嗎
或者用CFile::GetPosition和GetLength來比較撒(可能要注意考慮結束符)
virtual UINT Read( void* lpBuf, UINT nCount );
throw( CFileException );Return Value
The number of bytes transferred to the buffer. Note that for all CFile classes, the return value may be less than nCount if the end of file was reached.