码迷,mamicode.com
首页 > 其他好文 > 详细

打开文件程序

时间:2017-06-26 21:11:09      阅读:100      评论:0      收藏:0      [点我收藏+]

标签:fst   cin   文件   font   color   size   ace   turn   style   

 1 //打开文件
 2 #include <iostream>
 3 #include<fstream>
 4 
 5 using namespace std;
 6 
 7 int main()
 8 {
 9 
10     int a,b;
11     ifstream inData;
12 
13     inData.open("loan.txt");
14     if (!inData)
15     {
16         cout << "不能打开!!!" << endl;
17         return 1;                               //如果打开失败,终止程序;否则,打开空文件赋值随机
18     }
19 
20     inData >> a >> b;                           //赋值
21     cout << a+4+b;
22 
23     inData.close();
24 
25     cin.ignore();
26     cin.get();
27     return 0;
28 }

txt文件内容:

3
2

输出:

9

打开文件程序

标签:fst   cin   文件   font   color   size   ace   turn   style   

原文地址:http://www.cnblogs.com/skylover/p/7082093.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!