file processing, Random-access Files
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?
#include<iostream>
#include<fstream>
using namespace std;
void main(){
char firstname[10], lastname[10];
int age;
ofstream write("text.txt", ios::app);/*actually i am not sure what ios::app does*/
cout<<"firstname: ";
cin.getline(firstname,sizeof(firstname));
cout<<"last name: ";
cin.getline(lastname,sizeof(lastname));
cout<<"age: ";
cin>>age;
cin.ignore();
write<<firstname<<endl;
write<<lastname<<endl;
write<<age<<endl;
}
Derice
Junior Poster in Training
83 posts since Mar 2007
Reputation Points: 10
Solved Threads: 3
Some good links for File processing in C++ are here , here and here.
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
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.
WaltP
Posting Sage w/ dash of thyme
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
i hope to search for the word/phrase in my text file instead of print the whole text.
Derice
Junior Poster in Training
83 posts since Mar 2007
Reputation Points: 10
Solved Threads: 3
Read the links posted by me in the second post.
An eg.
string inStr;
string searchFor = "hello";
ostream in ("test.txt");
while (getline (in, inStr))
{
if (inStr == searchStr)
{
//process
}
}
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734