"ricky" <ri*******@yahoo.co.inwrote in message
news:11**********************@75g2000cwc.googlegro ups.com...
>I am a student doing internship. Iam doing a project.
I need to remove or update a line in the file.
So far
1.I can read from file
2. I can write to the file
3. I can find the string in the file i want to delete
Now,I want to take the input from one file and write all the infomation
to the new file except the one i don't want.
I can take the infrmation frm one file and write it to the new file and
delete the old file.
The only and imp bit i can't figure out is how to write all the
information except the one i dnt want
Would be something like
strncmp()
if(found)
here i want to write something that if found dnt write to new file
else
file<<all the lines;
Please help!!
#include <fstream>
#include <istream>
#include <iostream>
#include <ostream>
#include <string>
void omit(std::istream& in, std::ostream& out, const std::string s)
{
static std::string line;
while(std::getline(in, line))
if(line != s)
out << line << '\n';
}
int main()
{
const std::string in_name("input.txt");
const std::string out_name("output.txt");
std::ifstream input(in_name.c_str());
std::ofstream output(out_name.c_str());
if(!input)
std::cerr << "Cannot open input\n";
if(!output)
std::cerr << "Cannot open output\n";
if(input && output)
omit(input, output, "remove me");
if(!input.eof())
std::cerr << "Error reading input\n";
if(!output)
std::cerr << "Error writing output\n";
return 0;
}
-Mike