在这里的例子中:https://en.cppreference.com/w/cpp/chrono/high_resolution_clock/now https://en.cppreference.com/w/cpp/chrono/high_resolution_clock/now
他们声明了时钟时间点auto
.
auto start = std::chrono::high_resolution_clock::now();
文档说它返回“代表当前时间的时间点”。
但我不确定如何在下面的代码中声明,因为我习惯在函数开头声明变量,并且不知道将其声明为什么。这里已经简化了代码以显示我的意思。我该放什么???
?
我已经尝试过了auto
那里,但编译器不允许。auto orderRecvedTime;
给我这个错误:
error: non-static data member declared with placeholder 'auto'
#include <iostream>
#include <iterator>
#include <sstream>
#include <string>
#include <string.h>
//#include "load_symbol.h"
//#include "check_symbol.h"
#include "windows.h"
#include <vector>
#include <chrono>
using namespace std;
class order {
private:
string orderID;
??? orderRecvedTime;
char buysell;
string symbol;
double price;
int qty;
public:
void newOrder(string &_orderID, char &_buysell, string &_symbol, double &_price, int &_qty){
orderID = _orderID;
buysell = _buysell;
symbol = _symbol;
price = _price;
qty = _qty;
orderRecvedTime = std::chrono::high_resolution_clock::now();
}
};
int main() {
cout << "!!!Hello once more" << endl; // prints !!!Hello once more
vector<order> thebook;
string user_order = "";
string done = "done trading";
string orderID;
string orderaction;
string orderRecvedTime;
char buysell;
string symbol;
double price;
int qty;
while (user_order.compare(done) != 0) {
cout << "enter order"<< endl;
getline(cin, user_order);
stringstream lineStream(user_order);
lineStream >>orderaction>>orderID>> buysell >> symbol >> price>> qty;
order user_order;
if (orderaction.compare("D") == 0) {
cout << "you are making a new order."<< endl;
user_order.newOrder(orderID, buysell,symbol,price,qty);
thebook.push_back(user_order);
}
}
}