C++学习笔记一
2016-03-21 14:06
232 查看
一. VS 的输出数据保存到文本文件中:
#include<fstream>
//要包含的头文件
using namespace std;
int main()
{
ofstream ocout;
// 建立ofstream 对象
ocout.open("test.txt");
// 打开文件
ocout << "hello,C++";
//写入数据
ocout.close();
// 关闭文件
return 0;
}
二. 从文本中读入数据
#include<fstream>
// 要包含的头文件
#include<iostream>
using namespace std;
int main()
{
ifstream icin;
// 建立对象
icin.open("test.txt");
// 选择文本
char temp[100];
icin >> temp;
// 读入
cout << temp << endl;
system("pause");
return 0;
}
#include<fstream>
//要包含的头文件
using namespace std;
int main()
{
ofstream ocout;
// 建立ofstream 对象
ocout.open("test.txt");
// 打开文件
ocout << "hello,C++";
//写入数据
ocout.close();
// 关闭文件
return 0;
}
二. 从文本中读入数据
#include<fstream>
// 要包含的头文件
#include<iostream>
using namespace std;
int main()
{
ifstream icin;
// 建立对象
icin.open("test.txt");
// 选择文本
char temp[100];
icin >> temp;
// 读入
cout << temp << endl;
system("pause");
return 0;
}
相关文章推荐
- C语言调用驱动程序
- 2016年第七届蓝桥杯C/C++程序设计本科B组省赛 快速排序(代码填空)
- 2016年第七届蓝桥杯C/C++程序设计本科B组省赛 凑算式(结果填空)
- 2016年第七届蓝桥杯C/C++程序设计本科B组省赛 生日蜡烛(结果填空)
- 2016年第七届蓝桥杯C/C++程序设计本科B组省赛 煤球数目(结果填空)
- 使用C++日志库log4cplus
- 使用C++日志库log4cplus
- C语言中的强制类型转换
- 第七届蓝桥广东省赛B组C/C++题目
- ( C++) Access the hard drive.
- C/C++中void的作用,C/C++的语法对函数的一些影响
- c++ string 类的实现
- C指针一个小错误(2)-返回值不能是局部变量的指针
- c++关键字this
- C++ delete指针二次程序崩溃
- 【C++】《C++标准程序库》小结第十章-特殊容器
- 快速排序C++
- 使用C/C++写Python模块
- 基于流加密(stream cipher)下如何依靠多段密文获取特定密文的明文(c++实现)
- 设计模式--单例模式C++实现