Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 无法在C+;中创建包含日期和时间的文件名+;_C++_File_Stream_Ofstream - Fatal编程技术网

C++ 无法在C+;中创建包含日期和时间的文件名+;

C++ 无法在C+;中创建包含日期和时间的文件名+;,c++,file,stream,ofstream,C++,File,Stream,Ofstream,我有这个: std::ofstream * file = new std::ofstream(); if (seperator == 1) file->open("C:/Users/Max/Desktop/Sparade filer/" + name + ".txt"); else { std::string stamp = (std::string)__DATE__ + " : " + (std::string)__TIME__; file->open("C:/U

我有这个:

std::ofstream * file = new std::ofstream();
if (seperator == 1) file->open("C:/Users/Max/Desktop/Sparade filer/" + name + ".txt");
else 
{
    std::string stamp = (std::string)__DATE__ + " : " + (std::string)__TIME__;
    file->open("C:/Users/*directory*/" + name + " - " + stamp + ".txt");
}

*file << data;
delete file;
std::ofstream*文件=新std::ofstream();
如果(分隔符==1)文件->打开(“C:/Users/Max/Desktop/Sparade filer/”+name+“.txt”);
其他的
{
std::string stamp=(std::string)_日期__+“:”+(std::string)__;时间_;;
文件->打开(“C:/Users/*directory*/”+name+“-”+stamp+”.txt”);
}

*文件文件名不允许包含字符“:”

文件名不允许包含字符“:”

日期和时间返回程序编译的时间和日期。这与系统的日期和时间不同。如果这就是你想要的,那太好了

但是,如果您希望您的程序在每次运行时都在文件夹上标记更新的系统日期和时间,那么我建议您查看以下内容。TrungTN的答案是我面前的作品


我希望这有帮助

日期和时间返回程序编译的时间和日期。这与系统的日期和时间不同。如果这就是你想要的,那太好了

但是,如果您希望您的程序在每次运行时都在文件夹上标记更新的系统日期和时间,那么我建议您查看以下内容。TrungTN的答案是我面前的作品


我希望这有帮助

哈哈哈,如果真的是这样的话,那么我肯定觉得自己很愚蠢:p我会试着为约会找一个旁路,看看这是否有什么不同。编辑:暂时删除时间,现在它可以工作了。非常感谢!我会在6分钟内接受答案。哈哈哈,如果真是这样的话,那么我肯定会觉得自己很愚蠢:P我会尝试寻找一个日期旁路,看看是否有什么不同。编辑:暂时删除时间,现在它可以工作了。非常感谢!我会在6分钟内接受答案。