std

Posted fangjj215

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了std相关的知识,希望对你有一定的参考价值。

 

1.vector delete

    std::vector<string> strs;
    std::vector<string> strs;
    strs.push_back("asda1");
    strs.push_back("asda2");
    strs.push_back("asda3");
    strs.push_back("asda4");
    
    strs.erase(strs.begin() + 2);
    for (string s : strs)
    {
        mc::print(s);
    }

2.read file

void mc::readLines(std::string f, std::vector<std::string>& lines)
{
    std::ifstream ifile(f);
    std::string line;
    while (std::getline(ifile, line)) {
        lines.push_back(line);
    }
    ifile.close();
}

3.打印保留有效数字

#include <iostream>
#include <iomanip>

namespace mc
{
    template <typename T>
    void print(T a)
    {
        std::cout<< std::setprecision(10) << a << std::endl;
    }
}

 

 

以上是关于std的主要内容,如果未能解决你的问题,请参考以下文章