searching a disk file

This is a discussion on searching a disk file within the C++ Programming forums, part of the General Programming Boards category; Hi, i tried to compile the code below but got an error where SEEK_END and SEEK_CUR is. The error is: ...

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    23

    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.
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    May 2002
    Posts
    23
    Anyone?????
    Please i just need to know if the above code works on your compiler.

  3. #3
    Registered User
    Join Date
    May 2002
    Posts
    317
    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.

  4. #4
    Registered User
    Join Date
    May 2002
    Posts
    23
    Thanxs traveller. I think its about time for me to buy a good(new) book.

  5. #5
    Registered User
    Join Date
    May 2002
    Posts
    317
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sequential file program
    By needhelpbad in forum C Programming
    Replies: 80
    Last Post: 06-08-2008, 02:04 PM
  2. To find the memory leaks without using any tools
    By asadullah in forum C Programming
    Replies: 2
    Last Post: 05-12-2008, 08:54 AM
  3. Simple File encryption
    By caroundw5h in forum C Programming
    Replies: 2
    Last Post: 10-13-2004, 11:51 PM
  4. Making a LIB file from a DEF file for a DLL
    By JMPACS in forum C++ Programming
    Replies: 0
    Last Post: 08-02-2003, 09:19 PM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 02:58 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21