ofstream ofs; ofs.open("文件名", ios::out | ios::binary); if (!ofs.is_open()) { cout << "open out file fail!" << end;; return -1; } ofs.write(str.c_str(), strlen(str.c_str())); ofs.close();