Topic: file_get_contents in C++

Alright, I need a C++ program that will act like file_get_contents in PHP.

There will be a file on my server, and the C++ program needs to copy the contents of that file into a varible.

If this isnt easily possible in C++, but you know of another language, if you could post the full code here, and a compiler for it, id appreciate it alot.

Indocron
$theQuestion = (2*b) || !(2*b);

Re: file_get_contents in C++

mabe something on here might help?
http://www.phpconcept.net/index.en.php

or mabe not. i fail at life tongue

3 (edited by Jacq 2005-01-10 07:35)

Re: file_get_contents in C++

Hope this helps. This one copies a file to another char by char (Stroustrup, the c++ programming language 3rd ed. p 637). Just read the file to a buffer or a std::string instead.

// Note that I removed any error checking!

#include <fstream>

int main (int argc, char* argv[]) 
{
// check if anough arguments (=3)

std::ifstream from(argv[1]);
// check if file was opened (if(!from))

std::ofstream to(argv[2]);
// check if file was opened

char ch;

while (from.get(ch)) to.put(ch); //copy chars

// if(!from.eof() || !to) -- something strange happened here

return 1;
}

While you're at it I suggest you buy the book (late third edition ~20th printing or the special extreme edition).

Re: file_get_contents in C++

Well, this opens a file on the persons computer.

Basicly what im doing is making a script to check for upgrades to the game. So it needs to check an online file.

Indocron
$theQuestion = (2*b) || !(2*b);