【发布时间】:2013-09-25 07:43:24
【问题描述】:
我是 C++ 新手,我有疑问。
我有这样的代码:
void FlowState::closeFile() {
if (outfile) {
//from here
struct timeval times[2];
times[0] = myflow.tstart;
times[1] = myflow.tstart;
outfile->flush();
outfile->close();
//to here
}
}
我对所选部分有疑问。为什么我需要这个?效果如何?
这可能会有所帮助:
class FlowState {
public:
string flowid;
class Streamdemux &demux;
Flow myflow;
// ...
FlowState(class Streamdemux &demux_, const Flow &flow_,
u_int32_t isn_, bool tcp);
virtual ~FlowState();
// ...
};
还有:
class Flow: public flowAddr {
public:
int32_t vlan;
struct timeval tstart;
struct timeval tlast;
uint64_t packet_count;
uint64_t connection_count;
string fileNameTemplate;
Flow() :
vlan(), tstart(), tlast(), packet_count(), connection_count() {
fileNameTemplate = "%S:%s-%D:%d"; //brakuje ID połączenia
}
Flow(const flowAddr &flowAddr_, uint16_t vlan_,
const struct timeval &t1, const struct timeval &t2,
uint64_t connection_count_) :
flowAddr(flowAddr_), vlan(vlan_), tstart(t1), tlast(t2), packet_count(
0), connection_count(connection_count_) {
fileNameTemplate = "%S:%s-%D:%d";
}
virtual ~Flow() {
}
};
【问题讨论】:
-
您不需要刷新即将关闭的文件,关闭它会自动刷新它。
-
谁告诉你需要
struct timeval的东西? -
我得到了这样的代码,我想知道为什么会这样写