zoukankan      html  css  js  c++  java
  • c++ 文件

    读文件

    #include <fstream>
    #include <iostream>
    #include <random>
    #include <sstream>
    #include <string>
    
      std::ifstream inFile("d:\bigfile.txt");
    
      std::stringstream strStream;
      strStream << inFile.rdbuf();
      std::string grimmsTales = strStream.str();
    
      size_t size = grimmsTales.size();

    读取目录和层次

    #include <fstream>
    #include <iostream>
    #include <string>
    #include <filesystem>
    namespace fs = std::filesystem;
     
    int main()
    {
        fs::current_path(fs::temp_directory_path());
        fs::create_directories("sandbox/a/b/c");
        fs::create_directories("sandbox/a/b/d/e");
        std::ofstream("sandbox/a/b/file1.txt");
        fs::create_symlink("a", "sandbox/syma");
        for(auto i = fs::recursive_directory_iterator("sandbox");
                 i != fs::recursive_directory_iterator();
               ++i ) {
            std::cout << std::string(i.depth(), ' ') << *i;
            if(fs::is_symlink(i->symlink_status()))
                std::cout << " -> " << fs::read_symlink(*i);
            std::cout << '
    ';
        }
        fs::remove_all("sandbox");
    }

    随机数:

    #include <random>
    #include <string>
    #include <vector>
    
    
      // random values
      std::random_device seed;
      std::mt19937 engine(seed());
      std::uniform_int_distribution<> uniformDist(0, 100);
      std::vector<int> randValues;
      for (auto i = 0; i < access; ++i)
        randValues.push_back(uniformDist(engine));

    算耗时:

    #include <chrono>
    
      auto start = std::chrono::steady_clock::now();
      
    //do some thing time-consuming
    
      std::chrono::duration<double> durString =
          std::chrono::steady_clock::now() - start;
      std::cout << "duration:      " << durString.count() << " seconds"
                << std::endl;
  • 相关阅读:
    [BZOJ2179]FFT快速傅立叶
    [UOJ#34]多项式乘法
    [BZOJ4636]蒟蒻的数列
    [BZOJ4632]树的编码
    [BZOJ1070][SCOI2007]修车
    [BZOJ1529][POI2005]ska Piggy banks
    [BZOJ2654]tree
    腾讯应用管理中心,腾讯开放平台应用认领
    Sony/索尼 NW-ZX300A ZX300 无损音乐播放器4.4口
    read progress
  • 原文地址:https://www.cnblogs.com/bigben0123/p/14072886.html
Copyright © 2011-2022 走看看