Click to See Complete Forum and Search --> : can you change this code slightly for me


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.

MikeAThon
June 23rd, 2007, 12:05 PM
The sample is simple because it does something simple: a local copy of a local file

You want to do something complex: a local copy of a remote file located anywhere on the Internet. The code is correspondingly complex, and there's no way around that.

Try "Network Transfer Of Files Using MFC's CSocket Class" at http://www.codeproject.com/internet/SocketFileTransfer.asp

Mike