|
From: Jasin C. <tco...@st...> - 2003-02-26 03:53:33
|
why doesn't this work like i want it to, i would just like to read and =
write to the same file but it just won't do it. but if i add this =
ios::trunc to the fstream it works just fine, the file is empty. I am =
tryin to load a text file with a list of ip's and port numbers and some =
other garbage. All i want is the ip and port numbers when finished. =
example looks like this.
example.
200.63.21.82:8080 anon. 220 bps Argentina =20
200.32.86.100:80 anon. 413 bps Argentina
etc...
formatted look.
200.63.21.82:8080
200.32.86.100:80
etc... =20
#include <iostream>
#include <fstream>
#include <string>
#include <ios>
using namespace std;
int main(int argc, char* argv[])
{
string str;
string str2;
string garbage;
=20
if(argc < 2)
{
cerr << "Usage: proxysort inputfile" << endl; // see if program =
was called right
return -1;
}
fstream file1(argv[1], ios::in|ios::out);
/* loop through the entire file
and finding just the ip,port info
deleting the rest of the line until \n=20
*/
while(file1.good())
{
file1 >> str;
getline(file1, garbage); // ignore the rest of the =
line
file1 << str << endl;
}
file1.close();
return (0);
} |