C++ ~ stringstream write to file

stringstream ss;
ss << "ggggggggggg\n";

const std::string tmp = ss.str();
const char* cstr = tmp.c_str();

FILE *p = NULL;
char *file = "I:\\Hello.txt";

size_t len = 0;
p = fopen(file, "w");
if (p== NULL) {
cout <<"Error in opening a file..";
}

len = strlen(cstr);
fwrite(cstr, len, 1, p);
fclose(p);
cout<<"\nWritten Successfuly in the file.\n";

沒有留言: