在此示例中:https://en.cppreference.com/w/cpp/chrono/high_resolution_clock/now
他们用auto一词声明了时钟时间点。
auto start = std::chrono::high_resolution_clock::now();
并且文档说它返回'代表当前时间的时间点。'
但是我不确定如何在下面的代码中声明,因为我习惯于在函数的开头声明变量,而我不知道将其声明为什么。这里的代码已简化以显示我的意思。我要做什么? ?
我已经在那儿尝试过自动,但是编译器不允许这样做。
auto orderRecvedTime; --> gives me this error: 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);
}
}
return 0;
}
从调试器味精中拉出它,但是如果我这样声明它,它将进行编译。
std :: chrono :: _ V2 :: system_clock :: time_point orderRecvedTime;
std::chrono::high_resolution_clock::time_point orderRecvedTime;