C:
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
char * read_file(const char *path) {
int nsize = 0;
char* ptr = NULL;
FILE* file = fopen(path, "rb");
if (file)
{
fseek(file, 0, SEEK_END);
nsize = ftell(file);
fseek(file, 0, SEEK_SET);
ptr = (char*)malloc(nsize+1);
memset(ptr, 0, nsize + 1);
fread(ptr, 1, nsize, file);
fclose(file);
}
else
{
printf("open file fail ");
}
return ptr;
}
int main(int argc, char* argv[])
{
char *abc;
abc=read_file("test_config.json");
printf(abc);
return 0;
}
c++:
#include <string>
#include <fstream>
#include <iterator>
#include<iostream>
using namespace std;
string readFile(const string& filename) {
ifstream in(filename);
istreambuf_iterator<char> begin(in), end;
string content(begin, end);
in.close();
return content;
}
int main() {
string buffer=readFile("test_config.json");
std::cout << buffer;
return 0;
}