參考鏈接: http://blog.csdn.net/kingstar158/article/details/6859379
參考鏈接: http://www.weixueyuan.net/view/5825.html
參考鏈接: http://www.cnblogs.com/azraelly/archive/2012/04/14/2446914.html
參考鏈接: http://blog.csdn.net/lh3325251325/article/details/4761575
#include <fstream>
ofstream //文件寫操作 內存寫入存儲設備
ifstream //文件讀操作,存儲設備讀區到內存中
fstream //讀寫操作,對打開的文件可進行讀寫操作
//ios::in 爲輸入(讀)而打開文件
//ios::out 爲輸出(寫)而打開文件
//ios::ate 初始位置:文件尾
//ios::app 所有輸出附加在文件末尾
//ios::trunc 如果文件已存在則先刪除該文件
//ios::binary 二進制方式
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
int main()
{
ofstream location_out;
string ss;
ss = "(1, 2)";
location_out.open("F:/1.txt",ios::out | ios::ate); //std::ios::app以寫入和在文件末尾添加的方式打開.txt文件,沒有的話就創建該文件。
//std::ios::ate,先刪除以前的內容,再以寫入和在文件末尾添加的方式打開.txt文件,沒有的話就創建該文件。
if (!location_out.is_open())
return 0;
location_out << ss << endl;
location_out << "(" << 5 << "," << 10<< ")\n"; //將”(5,10) 回車”寫入.txt文件中
location_out.close();
}