Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/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++ popen调用中缺少数据_C++_Popen - Fatal编程技术网

C++ popen调用中缺少数据

C++ popen调用中缺少数据,c++,popen,C++,Popen,我的程序编译无误,并且似乎正确地完成了所有步骤。它应该进行php调用并返回数据。tcpdump确实显示请求发出,因此正在执行popen,但接收方从不更新。 我能找到的唯一差异是命令变量似乎缺少数据 #特罗 输出中的第二行是我发送给popen的命令 cout << command << endl; -> php coin.php 155 0.006387 cout我会尝试使用长浮点格式而不是浮点格式,因为biggestMark的类型应该作为双精度迭代器进行计算。我

我的程序编译无误,并且似乎正确地完成了所有步骤。它应该进行php调用并返回数据。tcpdump确实显示请求发出,因此正在执行popen,但接收方从不更新。 我能找到的唯一差异是命令变量似乎缺少数据

#特罗

输出中的第二行是我发送给popen的命令

cout << command << endl; ->  php coin.php 155 0.006387

cout我会尝试使用长浮点格式而不是浮点格式,因为biggestMark的类型应该作为双精度迭代器进行计算。我的意思是尝试更改sprintf(sendbuy、%f、*biggestMark)
sprintf(sendbuy,“%lf”,*biggestMark)。希望这会有所帮助。

这确实改善了情况。它并没有逐渐下降,而是干净利落地吃掉了最后两个。但仍然缺少最后两位数字:(我的最高价格是0.00521413,在第2位市场最高价格是0.00642538,在第0位/usr/bin/php/home/coinz/coin.php 155 0.006425 0.00642539,这与IEEE 754标准对浮点表示的限制不相关吗?特别是执行
*biggestMark+=1E-8
对浮点表示有点棘手点编号。尽量避免在代码中使用此类语句。与*biggestMark=*biggestMark+0.00000001的结果相同;
cout << command << endl; ->  php coin.php 155 0.006387
void mngr(){
        //vector defs
        vector<std::string> buydat;
        vector<std::string> markdat;
        vector<std::string> pricedat;
        vector<std::string> purchaseid;
        vector<double> doublePdat;
        vector<double> doubleMdat;
        doublePdat.reserve(pricedat.size());
        doubleMdat.reserve(markdat.size());
        char buybuff[BUFSIZ];
        char command[70];
        char sendbuy[12];
        buydat = getmyData();
        markdat = getmarketbuyData();
        //string match "Buy" and send results to new vector with pricedat.push_back()
        for(int b = 2; b < buydat.size(); b+=7){
                if ( buydat[b] == "Buy" ) {
                         pricedat.push_back(buydat[b+1]);
                }
        }
        transform(pricedat.begin(), pricedat.end(), back_inserter(doublePdat), [](string const& val) {return stod(val);});
        transform(markdat.begin(), markdat.end(), back_inserter(doubleMdat), [](string const& val) {return stod(val);});
        auto biggestMy = std::max_element(std::begin(doublePdat), std::end(doublePdat));
        std::cout << "my max price is " << *biggestMy << " at position " << std::distance(std::begin(doublePdat), biggestMy) << std::endl;
        auto biggestMark = std::max_element(std::begin(doubleMdat), std::end(doubleMdat));
        std::cout << "market max price is " << *biggestMark << " at position " << std::distance(std::begin(doubleMdat), biggestMark) << std::endl;
        if (biggestMy > biggestMark){
                cout << "Biggest is Mine!" << endl;
        }
        else if (biggestMy < biggestMark){
                //cout << "Biggest is market!";
                *biggestMark += 0.00000001;
                sprintf(sendbuy,"%f",*biggestMark);
                sprintf(command, "php coin.php 155 %s",sendbuy);
                FILE *markbuy = popen(command, "r");
                if (markbuy == NULL) perror ("Error opening file");
                while(fgets(buybuff, sizeof(buybuff), markbuy) != NULL){
                        size_t h = strlen(buybuff);
                        //clean '\0' from fgets
                        if (h && buybuff[h - 1] == '\n') buybuff[h - 1] = '\0';
                        if (buybuff[0] != '\0') purchaseid.push_back(buybuff);
                }

                cout << command << endl;
                cout << *biggestMark << endl;

        }
}