give me coding for search and edit a file in c++

Give me money and you have a deal

use fstream

@NathanOliver
its a forum to help not make money !

I know that. He wanted the code so I told him to give me money. It was an unresonable request like him just asking for code.

I've sometimes said that too -- it's a toung-in-cheek way of saying we aren't going to write the program. But ... if someone really puts a million dollars usd in my paypal I'll gladly see to it that he/she gets the program.

Yeah I wouldn't argue at that point.

give me coding for search and edit a file in c++

Can you supply an example of the types of files you wish to search ... and the types of editing that you wish to do?

Also, please show the code that you have coded so far, to do the desired job.

Its true you have to make an effort on your own behalf. But here is the sugar you are after. Read http://www.boost.org/doc/libs/1_55_0/libs/serialization/doc/index.html
(All of it!) and here is how to write and read - you can choose whether you want binary or text. Let me know if you need more help.

#include <iostream>
#include <fstream>
#include <boost\archive\xml_iarchive.hpp>    // XML In
#include <boost\archive\xml_oarchive.hpp>    // XML Out
#include <boost\archive\text_iarchive.hpp>   // Text In
#include <boost\archive\text_oarchive.hpp>   // Text Out
#include <boost\archive\binary_iarchive.hpp> // Binary In
#include <boost\archive\binary_oarchive.hpp> // Binary Out


int main()
{
    unsigned int iFlags = boost::archive::no_header;

    {
        // ofstream ofs("filename.txt", std::ios::trunc);
        ofstream ofs("filename.bin", std::ios::binary);

        //boost::archive::xml_oarchive oa(ofs, iFlags);
        //boost::archive::text_oarchive oa(ofs, iFlags);
        boost::archive::text_oarchive oa(ofs, iFlags);
        int i = 42;
        string s = "hello";
        oa << i << s;
    }
    {
        ifstream ifs("filename.bin", std::ios::binary);

        //boost::archive::xml_iarchive ia(ifs, iFlags);
        //boost::archive::text_iarchive ia(ifs, iFlags);
        boost::archive::text_iarchive ia(ifs, iFlags);
        int i = 9;
        string s;
        ia >> i;
        ia >> s;
        cout << i << " " << s.c_str();
    }

    cin.get();
    return 0;
}

It writes an integer and a string then reads it from a binary file. Read in the same way you have written out. I hope it starts you out on the right path.

Its true you have to make an effort on your own behalf. But here is the sugar you are after. Read boost.Serialization
(All of it!) and here is how to write and read - you can choose whether you want binary or text. Let me know if you need more help.

#include <iostream>
#include <fstream>
#include <boost\archive\xml_iarchive.hpp>    // XML In
#include <boost\archive\xml_oarchive.hpp>    // XML Out
#include <boost\archive\text_iarchive.hpp>   // Text In
#include <boost\archive\text_oarchive.hpp>   // Text Out
#include <boost\archive\binary_iarchive.hpp> // Binary In
#include <boost\archive\binary_oarchive.hpp> // Binary Out


int main()
{
    unsigned int iFlags = boost::archive::no_header;

    {
        // ofstream ofs("filename.txt", std::ios::trunc);
        ofstream ofs("filename.bin", std::ios::binary);

        //boost::archive::xml_oarchive oa(ofs, iFlags);
        //boost::archive::text_oarchive oa(ofs, iFlags);
        boost::archive::text_oarchive oa(ofs, iFlags);
        int i = 42;
        string s = "hello";
        oa << i << s;
    }
    {
        ifstream ifs("filename.bin", std::ios::binary);

        //boost::archive::xml_iarchive ia(ifs, iFlags);
        //boost::archive::text_iarchive ia(ifs, iFlags);
        boost::archive::text_iarchive ia(ifs, iFlags);
        int i = 9;
        string s;
        ia >> i;
        ia >> s;
        cout << i << " " << s.c_str();
    }

    cin.get();
    return 0;
}

It writes an integer and a string then reads it from a binary file. Read in the same way you have written out. I hope it starts you out on the right path.

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.