GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 04-May-2005, 19:28
walrus walrus is offline
New Member
 
Join Date: Apr 2005
Location: Istanbul/Turkey
Posts: 3
walrus is on a distinguished road

usage of seekg function


hi all!
i need some help with the usage of seekg function. in my code, i am getting characters from a text file. however i want to get a character in a predefined position. can i use seekg function for this purpose?
for instance my text is "abcdef". i have read 'e' and i want to return to the position of 'd'. how can i do this?
  #2  
Old 07-May-2005, 16:21
ubergeek ubergeek is offline
Regular Member
 
Join Date: Jan 2005
Posts: 775
ubergeek is a jewel in the roughubergeek is a jewel in the roughubergeek is a jewel in the rough
is this what you mean?
CPP / C++ / C Code:
#include <iostream>
#include <fstream>
using std::ifstream;
using std::streampos;
using std::cout;
using std::endl;
using std::cin;

int main()
{
ifstream infile("c:\\alphabet.txt"); //open a file. this file contains the text "abcdef"

char c;
streampos e_pos;

while (c = infile.get() != EOF)
{
if (c == 'e') e_pos = infile.tellg(); //save position of 'e'
}

cout << "character 'e' is at position " << e_pos << ". now jumping back to that position." << endl;
infile.seekg(e_pos); //recall to position of 'e'
cout << "character at position " << e_pos << " is " << infile.get() << "." << endl;
infile.close();
cin.get();
return 0;
}
hth,
The UberGeek
  #3  
Old 07-May-2005, 16:33
walrus walrus is offline
New Member
 
Join Date: Apr 2005
Location: Istanbul/Turkey
Posts: 3
walrus is on a distinguished road
actually this was not what i meant, however it'll be more useful than what i wanted to know! thanks a lot..
 
 

Recent GIDBlogStupid Management Policies by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[Include] Doubly-linked List dsmith C Programming Language 6 14-Apr-2006 14:12
[Tutorial] Function Pointers aaroncohn C++ Forum 4 17-Feb-2006 12:33
[GIM] gim.h dsmith C Programming Language 0 18-Jan-2005 09:48
Revising Script style ?????? pepee MySQL / PHP Forum 4 14-Apr-2004 05:59

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 04:13.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.