简体   繁体   English

打开输出流时出错

[英]Error in opening an output stream

In my code I'm opening an output stream and appending the data to the end of the file .. if there is no such file the stream should create one but the problem that it does not. 在我的代码中,我打开了一个输出流,并将数据附加到文件的末尾..如果没有这样的文件,该流应创建一个,但问题是它不会。

here is the code snippet: 这是代码片段:

char output_file[100];
strcpy(output_file, predicate.c_str());            
ofstream output_file_ptr1; 

output_file_ptr1.open(output_file,ios::out | ios::app | ios::binary );

if(output_file_ptr1.is_open()){

        output_file_ptr1 << subject <<" " << object <<"\n";
        output_file_ptr1.close();
}

else{
            printf("Error opening out file \n");
            return -1;
}

subject, object and predicate are variable strings that I created earlier. 主语,宾语和谓语是我之前创建的变量字符串。

Any idea it does not create the file? 知道它不会创建文件吗? + it is very important for me that the data is appended to the end of the file. +对我而言,非常重要的一点是将数据附加到文件末尾。

Update: predicate is the exact file name that I need , but it is not a usual naming ie 更新:谓词是我需要的确切文件名,但这不是通常的命名方式,即

< http://www.w3.org/1999/02/22-rdf-syntax-ns#type > < http://www.w3.org/1999/02/22-rdf-syntax-ns#type >

is an example 是一个例子

A value such as <w3.org/1999/02/22-rdf-syntax-ns#type> is not a valid file name in most environments. 在大多数环境中,诸如<w3.org/1999/02/22-rdf-syntax-ns#type>值都不是有效的文件名。 Unix-style operating systems (eg Linux) do not support "/" inside the file name (unless the directory structure matches). Unix风格的操作系统(例如Linux)在文件名中不支持“ /”(除非目录结构匹配)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM