944,098 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 4543
  • C++ RSS
Mar 19th, 2007
0

file processing, Random-access Files

Expand 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?
C++ Syntax (Toggle Plain Text)
  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.
Similar Threads
Reputation Points: 10
Solved Threads: 3
Junior Poster in Training
Derice is offline Offline
83 posts
since Mar 2007
Mar 19th, 2007
0

Re: file processing, Random-access Files

Some good links for File processing in C++ are here, here and here.
Super Moderator
Featured Poster
Reputation Points: 3241
Solved Threads: 719
Failure as a human
~s.o.s~ is offline Offline
8,873 posts
since Jun 2006
Mar 19th, 2007
0

Re: file processing, Random-access Files

Click to Expand / Collapse  Quote originally posted by Derice ...
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.
Moderator
Reputation Points: 3281
Solved Threads: 895
Posting Sage
WaltP is offline Offline
7,747 posts
since May 2006
Mar 19th, 2007
0

Re: file processing, Random-access Files

i hope to search for the word/phrase in my text file instead of print the whole text.
Reputation Points: 10
Solved Threads: 3
Junior Poster in Training
Derice is offline Offline
83 posts
since Mar 2007
Mar 19th, 2007
0

Re: file processing, Random-access Files

Read the links posted by me in the second post.

An eg.
C++ Syntax (Toggle Plain Text)
  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. }
Super Moderator
Featured Poster
Reputation Points: 3241
Solved Threads: 719
Failure as a human
~s.o.s~ is offline Offline
8,873 posts
since Jun 2006

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Pointers and Arrays? can anyone explain?
Next Thread in C++ Forum Timeline: Why am I getting this error?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC