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

Re: how to read file in c++ 80 80

Give me money and you have a deal

Re: how to read file in c++ 80 80

use fstream

@NathanOliver
its a forum to help not make money !

Re: how to read file in c++ 80 80

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.

Re: how to read file in c++ 80 80

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.

Re: how to read file in c++ 80 80

Yeah I wouldn't argue at that point.

Re: how to read file in c++ 80 80

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.

Re: how to read file in c++ 80 80

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.

Re: how to read file in c++ 80 80

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 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.