Thread: setting a file position pointer

  1. #1
    Registered User
    Join Date
    Jan 2011
    Posts
    101

    setting a file position pointer

    Can you please tell me how I set the pointer in a text file to a particular position?

    I want to set it at 150 and tried

    Code:
     ifstream jcin ( "Players.txt" );
     fseek ( jcin , 150 , SEEK_SET );
    But all I get is an error saying:
    Code:
    invalid conversion from 'void*' to 'FILE* {aka _iobuf*}' [-fpermissive]

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    You should use seekg. Take care to open the file in binary mode though.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Jan 2011
    Posts
    101
    Thanks laserlight - easy when you know how isn't it?

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Yeah, it is easy when you know how and where to look things up
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. setting cursor position
    By scrasnu in forum C Programming
    Replies: 1
    Last Post: 10-04-2008, 10:28 AM
  2. Getting and setting cursor position
    By Spartan552 in forum Linux Programming
    Replies: 8
    Last Post: 01-14-2008, 05:27 AM
  3. Savign the position of a pointer in an input file
    By earth_angel in forum C++ Programming
    Replies: 13
    Last Post: 07-08-2005, 03:39 PM
  4. Setting a pointer to file data
    By RobbieMc in forum C++ Programming
    Replies: 1
    Last Post: 03-19-2005, 11:29 AM
  5. Position FILE pointer to a specified line of Text file
    By jessica_xie in forum C Programming
    Replies: 2
    Last Post: 02-04-2005, 03:52 PM