错误:函数&st; :: vector的参数太少

时间:2014-11-24 07:39:53

标签: c++ c++11 vector

当我尝试访问我的函数时,我收到编译错误 该程序从两个不同的源检索数据,并且应该在一个函数中汇总。

k.cpp: In function 'int main()':
k.cpp:65:10: error: too few arguments to function 'std::vector<std::basic_string<char> > buymngr(FILE*)'
k.cpp:45:26: note: declared here

这表明我在这里缺少一个参数 - &gt; std :: vector buymngr(FILE * buyfp) 我只是不确定它的要求。

#include <cstdio>
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <unistd.h>
#include <cstring>
#include <cstdlib>
#include <vector>

using namespace std;

FILE *init( const char *fname ){
        FILE *buyfp = popen( fname, "r" );
        return buyfp;
}

vector<string> getmyData()
{
        FILE *fp = popen("php orders.php 155", "r");
        if (fp == NULL) perror ("Error opening file");
        char buff[BUFSIZ];
        vector<string> vrecords;
        while(fgets(buff, sizeof(buff), fp) != NULL){
                size_t n = strlen(buff);
                if (n && buff[n - 1] == '\n') buff[n - 1] = '\0';
                if (buff[0] != '\0') vrecords.push_back(buff);
        }
        return vrecords;
}

std::vector<std::string> getmarketbuyData(FILE *buyfp){
        char buff2[BUFSIZ];
        vector<std::string> vrecs;
        while(std::fgets(buff2, sizeof buff2, buyfp) != NULL){
                size_t n = std::strlen( buff2 );
                if ( n && buff2[n-1] == '\n' ) buff2[n-1] = '\0';
                if ( buff2[0] != '\0' ) vrecs.push_back( buff2 );
        }
        for(int t = 0; t < vrecs.size(); ++t){
                cout << vrecs[t] << " " << endl;
        }
                return vrecs;
}

std::vector<std::string> buymngr(FILE *buyfp){
        vector<std::string> buydat;
        vector<std::string> markdat;
        buyfp = init("php buyorders.php 155");
        if (buyfp == NULL) perror ("Error opening file");
        if ( buyfp ){
                buydat = getmarketbuyData( buyfp );
        }
        for(int b = 0; b < sizeof(buydat); ++b){
                cout << buydat[b] << " " << endl;
        }
        markdat = getmyData();
        for(int l = 0; l < sizeof(markdat); ++l){
                cout << markdat[l] << " " << endl;
        }
}

//Le Main
int main(void)
{
        buymngr(FILE*);
}

如何摆脱错误?它要求什么参数?

1 个答案:

答案 0 :(得分:1)

您的定义如下: -

std::vector<std::string> buymngr(FILE *buyfp)

所以它期待FILE *类型作为它的参数,而你正在调用它: -

buymngr();

没有任何论据。