玄元一墨 发表于 2023-2-20 15:03:13

C++的file_put_contents()方法

#include <iostream>
#include <fstream>
#include <string>

#include <windows.h>

#define PHP_EOL "\n"

using namespace std;

bool file_put_contents(string fileName , string fileContents)
{
    ofstream file;
    file.open(fileName, ios::out);
    // 若文件打开失败
    if (!file.is_open())
    {
      return false;
    }
    file << fileContents << endl;
    file.close();
    return true;
}

}

int main()
{
    file_put_contents("嘤嘤嘤.txt", "嘤嘤嘤" PHP_EOL "嘤嘤嘤2");
       

        system("pause");

        return 0;
}




这C++是不是有一股PHP的味道?{:4_110:}
页: [1]
查看完整版本: C++的file_put_contents()方法