zoukankan      html  css  js  c++  java
  • C++代码片

    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 }
    View Code

    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 }
    View Code
  • 相关阅读:
    Windows下载Vim
    分享:分享几个程序员使用的网站
    分享:C语言大礼包(PDF)
    将vscode打造成强大的C/C++ IDE
    最适合做C/C++开发的IDE
    bzoj 2244
    bzoj 1492
    bzoj 3262
    bzoj 1176
    bzoj 2961
  • 原文地址:https://www.cnblogs.com/winslam/p/12780385.html
Copyright © 2011-2022 走看看