我的循环输出数据不正确。我有7个集合的入站Web数据。我试图将7个记录插入到一个向量中,然后显示向量内容后跟一个新行。
char buff[BUFSIZ];
FILE *fp = stdout;
char * cstr = buff;
vector<std::string> vrecords;
while(std::fgets(buff, sizeof buff, fp) != NULL){
for(int i = 0; i < 7; ++i){
vrecords.push_back(buff);
}
if (!strcmp(cstr, "Buy\n")) {
printf("Found buy!\n");
for(int t = 0; t < vrecords.size(); ++t){
cout << vrecords[t] << " ";
}
}
if (!strcmp(cstr, "Sell\n")) {
printf("Found sell!\n");
}
cout << endl;
}
输出:
预期产出:
Found buy!
198397652
2014-11-14 15:10:10
Buy
0.00517290
0.00100000
0.00100000
0.00000517
Found buy!
198397685
2014-11-14 15:10:13
Buy
0.00517290
0.00100000
0.00100000
0.00000517
Found buy!
198398295
2014-11-14 15:11:14
Buy
0.00517290
0.00100000
0.00100000
0.00000517
Found sell!
203440061
2014-11-21 16:13:13
Sell
0.00825550
0.00100000
0.00100000
0.00000826
入站数据:
198397652
2014-11-14 15:10:10
Buy
0.00517290
0.00100000
0.00100000
0.00000517
198397685
2014-11-14 15:10:13
Buy
0.00517290
0.00100000
0.00100000
0.00000517
198398295
2014-11-14 15:11:14
Buy
0.00517290
0.00100000
0.00100000
0.00000517
203440061
2014-11-21 16:13:13
Sell
0.00825550
0.00100000
0.00100000
0.00000826