void maintainFileName()
{
std :: ifstream myfile;
myfile.open ("zoomLevels.txt");
if (myfile.is_open())
{
// Move to end of the file,
myfile.seekg (0, std::ios::end);
// and then six characters back to pick up the last file number.
myfile.seekg (6, std::ios::beg);
int len = 1;
char *t = new char[len];
myfile.read(t, len);
qDebug() << "\nt: " << *t << "\n";
}
else
{
qDebug() << "\nsorry";
}
}
該文件包含此:如何從文件末尾讀取第6個字符 - ifstream?
78.8115,29.582,1,01.rda
78.8115,29.582,2,02.rda
76.3671,30.2201,1,11.rda
76.3671,30.2201,2,12.rda
78.1908,30.3007,1,01.rda
78.1908,30.3007,2,02.rda
77.3284,29.1415,1,01.rda
77.3284,29.1415,2,02.rda
77.3064,29.1655,1,01.rda
77.3064,29.1655,2,02.rda
由該函數返回的值是5
,而從最終的第六個字符是0
!
我哪裏錯了?
你得到了'dir'參數錯誤的含義。這不是一個方向!你可能不是第一個被抓到的人:這完全是一種誤導:它實際上是一個位置! –
@ J.N。看到這個:http://www.cplusplus.com/reference/iostream/istream/seekg/它寫在那裏:'尋找方向'。 :) –
相當於鏈接:「**正在尋找方向**它是一個ios_base :: seekdir類型的對象,它指定了應用偏移參數off的位置的絕對位置**。方向/絕對位置。難怪人們會感到困惑。 – jrok