1、代码测时间/代码耗时/代码速度/代码效率

1 #include<opencv2/opencv.hpp> 2 3 #include<chrono> 4 using namespace std; 5 6 int main() 7 { 8 9 chrono::steady_clock::time_point t1 = chrono::steady_clock::now(); 10 11 // TODO 12 cv::waitKey(1357); // the cost time should be 1357 ms 13 14 chrono::steady_clock::time_point t2 = chrono::steady_clock::now(); 15 chrono::duration<double> time_used = chrono::duration_cast<chrono::duration<double>>(t2 - t1); 16 cout << "the cost of time:" << 1000 * time_used.count() << " milliseconds." << endl; 17 18 return 1; 19 }
2、从文本逐行读取文件(eg:读取序列图等)

1 void readStringList(const string& filename, vector<string>& idxs) 2 { 3 ifstream file; 4 file.open(filename.c_str()); 5 while (!file.eof()) 6 { 7 string str; 8 std::getline(file, str); 9 //file >> str; 10 idxs.push_back(str); 11 } 12 file.close(); 13 }