file processing, Random-access Files

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Mar 2007
Posts: 68
Reputation: Derice is an unknown quantity at this point 
Solved Threads: 1
Derice Derice is offline Offline
Junior Poster in Training

file processing, Random-access Files

 
0
  #1
Mar 19th, 2007
i am a newbie in C++ file processing...
Any1 can guide me to search for an item(lastname) in the example below?
what is seekg or seekp... how to use it?
  1. #include<iostream>
  2. #include<fstream>
  3. using namespace std;
  4.  
  5. void main(){
  6. char firstname[10], lastname[10];
  7. int age;
  8.  
  9. ofstream write("text.txt", ios::app);/*actually i am not sure what ios::app does*/
  10.  
  11. cout<<"firstname: ";
  12. cin.getline(firstname,sizeof(firstname));
  13. cout<<"last name: ";
  14. cin.getline(lastname,sizeof(lastname));
  15. cout<<"age: ";
  16. cin>>age;
  17. cin.ignore();
  18.  
  19. write<<firstname<<endl;
  20. write<<lastname<<endl;
  21. write<<age<<endl;
  22. }
Last edited by ~s.o.s~; Mar 19th, 2007 at 1:04 pm. Reason: Removed the weird coloring and fixed code tags, learn to use them.
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,642
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 472
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: file processing, Random-access Files

 
0
  #2
Mar 19th, 2007
Some good links for File processing in C++ are here, here and here.
I don't accept change; I don't deserve to live.

Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,117
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 282
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: file processing, Random-access Files

 
0
  #3
Mar 19th, 2007
Originally Posted by Derice View Post
i am a newbie in C++ file processing...
Any1 can guide me to search for an item(lastname) in the example below?
what is seekg or seekp... how to use it?
Not a clue what you are asking. Maybe you need to explain the problem. Remember, we're new to it so details will help.
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 68
Reputation: Derice is an unknown quantity at this point 
Solved Threads: 1
Derice Derice is offline Offline
Junior Poster in Training

Re: file processing, Random-access Files

 
0
  #4
Mar 19th, 2007
i hope to search for the word/phrase in my text file instead of print the whole text.
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,642
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 472
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: file processing, Random-access Files

 
0
  #5
Mar 19th, 2007
Read the links posted by me in the second post.

An eg.
  1. string inStr;
  2. string searchFor = "hello";
  3. ostream in ("test.txt");
  4.  
  5. while (getline (in, inStr))
  6. {
  7. if (inStr == searchStr)
  8. {
  9. //process
  10. }
  11. }
I don't accept change; I don't deserve to live.

Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC