如何通过字符串新建文件
程序代码:
#include <iostream> #include <string> #include <vector> #include <fstream> #include <ctime> using namespace std; int main() { time_t t; t = time(&t); string timestamp = ctime(&t); timestamp.erase(timestamp.end()-1); timestamp += ".cpp"; cout << timestamp << endl; const string address_path = "d:\\"; string filename_new = address_path + timestamp; cout << filename_new; outfile.open(filename_new.c_str()); outfile << "this"; outfile.close(); }
按理说不是应该在该路径下新建cpp文件的吗?为什么没有文件?如果直接用outfile.open("c:\\a.cpp")可以生成文件。。。