您的位置:首页 > 编程语言 > C语言/C++

c++创建txt文件,并写入内容

2016-04-11 17:49 543 查看
参考链接: /article/2319277.html

参考链接: http://www.weixueyuan.net/view/5825.html

参考链接: /article/5931334.html

参考链接: /article/3587425.html

以上大神解释的非常详细和全面,很多暂时用不到的就不列了,以下是自己的应用

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

int main()
{
ofstream location_out;
string ss;
ss = “(1, 2)”;
location_out.open("location_out.txt", std::ios::out | std::ios::app);  //以写入和在文件末尾添加的方式打开.txt文件,没有的话就创建该文件。
if (!location_out.is_open())
return 0;

location_out << ss << endl;
location_out <<“(”<< 5 << “,” << 10 << “) \n”  ;     //将”(5,10) 回车”写入.txt文件中

location_out.close();
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: