2014-01-10 231 views
0

我对cpp仍然很缺乏经验。将ostream重定向到输出文件

我有我想从.cpp文件调用一个函数,下面是它的头:

int wsq_encode(unsigned char* bufferRAW, int width, int height, char compressRate, std::ostream &streamWSQ); 

我需要写打开万吨的RAW图像格式的编码(bufferRAW)和压缩他们根据这家公司的算法对.wsq进行处理,一直使用argv []使用宽度,高度和压缩率参数。输出文件应该转到streamWSQ。

wsq_encode已关闭,我不会进入它。我无法将输出文件传递给wsq_encode。我需要编写的代码非常简单:

#include "../inc/libcorewsq.h" 
#include <fstream> 
#include <iostream> 
#include <stdio.h> 
#include <stdlib.h> 
#include <string.h> 

int main (int argc, char **argv) { 
     unsigned char raw[20]; 
     strcpy ((char*)raw, argv[1]); 
     int width = atoi(argv[2]); 
     int height = atoi(argv[3]); 
     ostream arq; 
     arq.open ("out.wsq"); 
     wsq_encode (raw, width, height, 5, arq); 

     return 0; 
} 

我还在为如何做到这一点做斗争。我需要在CentOS ssh shell中使用GCC 4.4.7进行编译和运行。

+0

解释你的“麻烦”。 –

+0

我需要调用的函数接受一个ostream参数来写输出。如果我尝试限定std :: ostream或添加“using namespace std;”,错误消息 “对wsq_encode(unsigned char *,int,int,char,std :: basic_ostream >&)'“ 随之而来,即使有#include”../inc/libcorewsq.h“。 – user3182973

+0

'#include'是无关紧要的。您无法在函数的_definition_中链接。 –

回答

0

#include是无关紧要的:你没有链接功能的定义。

1

尝试使用std::ofstream,其中f用于文件。

开放std::ostream打开通用输出流。