C++写txt的时候可以用到std::ofstream来实现。

代码:

#include <stdlib.h>
#include <fstream>
#include <string>
#include <iostream>

int main(int argc, char* argv[])
{
    std::ifstream fIn("str.txt");
    std::ofstream fOut("str2.txt");
    if (!fIn)
    {
        std::cout << "Open input file faild." << std::endl;
    }
    if (!fOut)
    {
        std::cout << "Open output file faild." << std::endl;
    }
    std::string str;
    while (std::getline(fIn, str))
    {
        std::cout << str << std::endl;
        fOut << str << std::endl;
    }
    fIn.close();
    fOut.close();
    system("pause");
    return 0;
}

凤兮凤兮何德之衰。

往者不可谏。

来者犹可追。

已而已而。

今之从政者殆而。

相关文章:

  • 2022-02-11
  • 2022-12-23
  • 2022-01-22
  • 2022-02-11
  • 2022-12-23
  • 2021-08-07
  • 2022-12-23
  • 2021-04-17
猜你喜欢
  • 2022-12-23
  • 2021-08-08
  • 2022-12-23
  • 2022-01-23
  • 2022-12-23
  • 2021-12-12
相关资源
相似解决方案