Learn when you want, where you want with convenient online training courses. Sign up now!
Experts Exchange Solution brought to you by
"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.
Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.
#include <stdio.h> // contains file i/o declarations
#include <malloc.h> // contains malloc's declaration
FILE* f; // pointer to a file
long fsize; // long that will contain file size
f = fopen("myfile.xml", "rb"); // opens the file "./myfile.xml" for reading in binary mode
fseek(f , 0 , SEEK_END); // goes to the end of the file
fsize = ftell(f); // tells length of file from start to current position (end)
rewind(f); // goes to the start of the file
char* cstr = malloc(sizeof(char) * fsize); // allocates memory for a c string equal to the length of the file
fread(cstr, 1, fsize, f); // reads the entire file into cstr
fclose(f); // closes file
Open in new window
Explore SharePoint 2016, the web-based, collaborative platform that integrates with Microsoft Office to provide intranets, secure document management, and collaboration so you can develop your online and offline capabilities.
template <typename T>
T readFile(const std::string& filename)
typedef std::istreambuf_iterator<char> Citr;
std::ifstream fin(filename.c_str(),std::ios::binary | std::ios::in);
CString str = readFile<string>("x.cpp").c_str();
std::cout << str;
From novice to tech pro — start learning today.
Premium members can enroll in this course at no extra cost.