newbie421
June 22nd, 2007, 08:44 PM
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main () {
string line;
ifstream myfile ("example.txt");
if (myfile.is_open())
{
while (! myfile.eof() )
{
getline (myfile,line);
ofstream myfile2("example2.txt", ios::app);
myfile2 << line << endl;
}
myfile.close();
}
else cout << "Unable to open file";
system("pause");
return 0;
}
I got this code from online, I just changed it a little so now it copies the contents of one file and creates another with the same stuff. The problem I have is I need to download a file remotely so I know I'll have to copy the stuff into a buffer of char type or something but here I have is string so can someone help me change this code a little. Like to use the send, recv functions it wont accept string so can someone help? Most codes I've searched for I find them somewhat difficult to understand but this one is really simple so maybe an equivalent of this code that actually works is what I'm looking for.
#include <fstream>
#include <string>
using namespace std;
int main () {
string line;
ifstream myfile ("example.txt");
if (myfile.is_open())
{
while (! myfile.eof() )
{
getline (myfile,line);
ofstream myfile2("example2.txt", ios::app);
myfile2 << line << endl;
}
myfile.close();
}
else cout << "Unable to open file";
system("pause");
return 0;
}
I got this code from online, I just changed it a little so now it copies the contents of one file and creates another with the same stuff. The problem I have is I need to download a file remotely so I know I'll have to copy the stuff into a buffer of char type or something but here I have is string so can someone help me change this code a little. Like to use the send, recv functions it wont accept string so can someone help? Most codes I've searched for I find them somewhat difficult to understand but this one is really simple so maybe an equivalent of this code that actually works is what I'm looking for.