-
searching a disk file
Hi, i tried to compile the code below but got an error where SEEK_END and SEEK_CUR is. The error is: 'Error could not find a match for 'istream::seekg(long,int)'
The code below is an example from a book ,the alph.txt is a text file containing the letters of the alphabet (atached)and the program below prints them on the screen in reverse order . Am using borland TC 3.0 compiler. Please if you could compile the code and tell me if it works for you, or if am doing something wrong.
Thanxs for your help.
[CODE]
----------------------------------------------------------------------------------
#include <fstream.h>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
ifstream fp;
void main()
{
char in_char;
fp.open("Alph.txt", ios::in);
if(!fp)
{
cout<<"**Error opening file**\n";
exit(0);
}
fp.seekg(-1l,SEEK_END);
for(int ctr=0; ctr<26; ctr++)
{
fp>>in_char;
fp.seekg(-2l, SEEK_CUR);
cout<<in_char;
}
fp.close();
return;
}
-----------------------------------------------------------------------------
p.s To make the above program work instead of
(-1l, SEEK_END) i used (-1l, ios::end)
Is there any difference between this two comands ?
As you can tell am new to programming so i would apriciate any
comments that can help me. Thanxs.:)
-
Anyone?????
Please i just need to know if the above code works on your compiler.
-
Code:
#include <fstream.h>
#include <iostream.h>
#include <stdlib.h>
ifstream fp;
void main()
{
char in_char;
fp.open("Alph.txt", ios::in);
if(!fp)
{
cout<<"**Error opening file**\n";
exit(0);
}
fp.seekg(-1l,ios::end);
for(int ctr=0; ctr<26; ctr++)
{
fp>>in_char;
fp.seekg(-2l, ios::cur);
cout<<in_char;
}
fp.close();
return;
}
The problem is that the book you are using is old.
-
Thanxs traveller. I think its about time for me to buy a good(new) book.
:D
-
Hey no problem. If your just starting out or in the intermediate level may I suggest 'C++ Primer Plus' by Stephen Prata. It is a Sams book, and some their are some errors but nothing too major. I picked it up and read it from start to finish and have no complaints. It is a really good way to cement your knowledge and/or expand it.