read text from file and return it from function

Hi!

I´m pretty new to C++ and I want to create a function that reads all content from a .txt file to a "something" (I thought a char array would do the trick) and I then want to return the file content (i e the char array) from the function back to main{}.

Wherever I look I only find how do read line-wise and then handling the information within the function, how do I get the data from the file to my array and then to the main function?

Best Regards

Fredrik
You can use the read method http://www.cplusplus.com/reference/iostream/istream/read/
But if the file is quite large, reading it at once may not be a good idea

( Or you can read line by line and add up the various lines )
The way I do something simular to this is to create the char array in main(...) then pass a pointer to that array to the function reading the file.
Computergeek01: Ah, that is a great idea! Thanks! I´ll try it and let you know if it works out.
Topic archived. No new replies allowed.