首页 > 编程语言 > 详细

[C++] C++ 文件操作

时间:2015-12-26 16:50:31      阅读:227      评论:0      收藏:0      [点我收藏+]

一、需要的头文件

#include <fstream>

#include <sstream>

using namespace std;

 

二、打开关闭

ifstream file;

file.open(string name,ios::in);

第二个参数默认是ios::in

file.close();

 

三、读取

为了便于处理,使用字符串流

istringstream stream(string line);

可以使用下面的方式来进行使用:

while(getline(file,line)){
      istringstream stream(line);
      double a;
      while(stream>>a){
           cout<<a<<" ";
      }
  cout<<endl;
}     

 

[C++] C++ 文件操作

原文:http://www.cnblogs.com/deepblueme/p/5078281.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!