PDA

Click to See Complete Forum and Search --> : Weird File I/O question


Dec 23rd, 2000, 05:01 PM
Ok, i want to find out if a file contain this string on the first line...

~~~blah blah blah~~~

(Any thing can be on the next lines)

And if it does delete it from the file, and make the line after that line the first line.

Any ideas?

Vlatko
Dec 24th, 2000, 04:24 AM
Hre is the code to find the string in the first line but for making it the first line i am not sure how.

#include <iostream.h>
#include <string>
#include <fstream>
using namespace std;

int main(int argc, char* argv[])
{
ifstream ifile("c:\\textfile.txt");
string text;
getline(ifile,text);
int pos = text.find ("~~~blah blah blah~~~",0); //if pos != -1 then string found
cout<<pos<<endl;

return 0;
}

Dec 24th, 2000, 09:28 AM
if you are using namespace std you can't include .h on iostream either...