C++ ~ stringstream sample

void saveToTxt(stringstream& ss){
FILE *p = NULL;
char *file = "I:\\Hello.txt";

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

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";

}



stringstream ss;
ss << "caaaaaaaaaaaaaa\n";
saveToTxt(ss);

沒有留言: