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;
}

Recommended Answers

All 4 Replies

Some good links for File processing in C++ are here, here and here.

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.

i hope to search for the word/phrase in my text file instead of print the whole text.

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
    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.