-1
我需要編寫一個程序來讀取文件中的某些字符。例如:從開始到結束或以相反順序的所有字符。我怎樣才能顯示所有的角色而不是一個?使用seekg需要幫助
//This program reads a file from beg to end, end to beg, beg to 4th position,
//8th to 15th position, end to 3rd position, and 22nd to end
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
char letter; //holds the character
fstream file("alphabet.txt", ios::in);
file.seekg(5L, ios::beg);
file.get(letter);
cout << "Beginning to the 4th letter: " << letter << endl;
file.seekg(-22L, ios::end);
file.get(letter);
cout << "21st letter to the end: " << letter << endl;
file.close();
system("pause");
return 0;
}
你的問題是什麼? – michaelc35 2014-11-06 22:10:54
那麼問題是什麼? – PaulMcKenzie 2014-11-06 22:11:26
如何顯示從頭到尾的所有字符?反之亦然? – anonymous1126 2014-11-06 22:13:54